I am building a database architecture. I also have read this guide So I will have following models:
Author
name, has_many:questions, has_many:comments, has_many:edits
Question
title, body , author_id, has_many:comments, belongs_to:author
Comment
body, question_id, author_id, belongs_to:question, has_many:edits, belongs_to:author
Edit
body, comment_id, author_id, belongs_to:comment, belongs_to:author
As you can see, question can have many comments and each comment can have many edits. And author can have many questions, edits and comments
Main question is: did I use has_many
and belongs_to
assosiations correctly?!
Additional info: I don't know if it is relevant, but I want to use following scaffold migrations:
rails generate scaffold Question title:string body:text author_id:integer has_many:comments belongs_to:author
rails generate scaffold Comment body:text question_id:integer author_id:integer belongs_to:question has_many:edits belongs_to:author
rails generate scaffold Edit body:text comment_id:integer author_id:integer belongs_to:comment belongs_to:author
rails generate scaffold Author name:string has_many:questions has_many:comments has_many:edits
UPD: My scaffolds are incorrect. I should use something like this:
rails generate scaffold Question title:string body:text user:references
rails generate scaffold Comment body:text user:references question:references
rails generate scaffold Edit body:text user:references question:references