You really need to learn about rails and not directly modify that database. What I did was find a rails book and read it. And at some point I also looked at a Ruby book. Iām old enough to remember when books were the only way to learn about computers. As I understand it, there are many sites on the internet that can give you a Rails tutorial. I think that there is a way that you can search the internet to find them.
Here is one that I found
Hereās how to update stuff with rails, but reading one of those guides will quickly give you an idea of how it works.
t=Topic.find(123)
t.title='my new title'
t.save
# or
t.update(title: 'my new title')
When you do stuff through Rails it does a bunch of checks if stuff. These things will usually keep you from making huge mistakes. You probably shouldnāt break those rules until you understand them.
For example, if you want users to create topics in a certain category via the API, then they need to have rights to create a topic in that category. If you really want to have a topic created by a user to exist in a category he doesnāt have rights to, then create it if another category and then have an admin move it (or do it via rails, which wonāt enforce category permissions).
Although this could easily cause an exception (which you are advised to rescue), so you might want to use find_by as an alternative which will return nil rather than raising an exception, depending on how you want to manage things.
Thatās how weāre the same. I needed to do some sql with a complicated inner join and another with a simple union that I got the ai to help with. I shaker if I had paid a bit more attention in my database class in 1986 Iād have known how to do it.
Why not get the ai to write rails commands for you?
For standard select, where, sort, limit queries, I write this myself, but anything more complicated, I now as the AI. I asked the AI:
write a query that shows a category and then lists the top 5 topic starters for that category and the number of topics they started
And immediately it gave back (this is a non-discourse DB):
WITH TopTopicStarters AS (
SELECT
c.id AS category_id,
c.name AS category_name,
u.name AS user_name,
COUNT(t.id) AS num_topics_started,
ROW_NUMBER() OVER(PARTITION BY c.id ORDER BY COUNT(t.id) DESC) AS rank
FROM topics t
JOIN categories c ON t.category_id = c.id
JOIN users u ON t.user_id = u.userid
GROUP BY c.id, u.name
)
SELECT
c.category_name,
tts.user_name,
tts.num_topics_started
FROM categories c
JOIN TopTopicStarters tts ON c.id = tts.category_id
WHERE tts.rank <= 5;
No way could I have come up with that without a lot of googling and trial and error!