Models would actually be so.
class Post < ActiveRecord::Base
has_many :comments
end
class Comment < ActiveRecord::Base
belongs_to :status
belongs_to :post
end
class Status < ActiveRecord::Base
has_many :comments
end
Simple one to many relationships.
gives you following instance methods
Post#comments
Comment#post
Comment#status
Status#comments
Does that make sense?
Cam
On 10/01/2009, at 6:54 AM, sohdubom wrote:
>
> as an example i thought that the following case could be a good one
> for has_one relationship, but i ended up very confused:
>
> - suppose i have a Comment model with attributes: author, content,
> status (just 3 to simplify)
>
> - i wouldn't do that in a real scenario, but let's say i don't want to
> create enums for status and decide to normalize it by creating an
> extra model: Status
>
> in this case: a comment has_one status (like new, ok, bad, ...), so
> the Comment model will have as fk: status_id and status belongs_to
> comment (in singular) or status belongs_to comments (plural) ?
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
or Rails Oceania" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rails-oceania?hl=en
-~----------~----~----~----~------~----~------~--~---