A status in your example would "has_many" comments, as many comments  
can have the same status. Therefore, a comment would belongs_to a  
status.
-----
Ryan Bigg
Freelancer
http://frozenplague.net







On 10/01/2009, at 11:41 AM, Matt wrote:

> That's not a great case for the has_one association because as you  
> pointed out, the real world usage probably isn't there.
>
> Here's a couple for you
>
> class Student < ActiveRecord::Base
>   # so in here, there's an id, name for the student and any other  
> details they may have
>   has_one :locker
> end
>
> class Locker < ActiveRecord::Base
>   # here you have the fields id, locker_number, student_id (this is  
> the one for the association)
>   belongs_to :student
> end
>
> ---
>
> class Sale < ActiveRecord::Base
>   # id and whatever other fields
>   has_one :invoice
> end
>
> class Invoice < ActiveRecord::Base
>   # id, sale_id, any other fields you want
>   belongs_to :sale
> end
>
> Do they help at all?
>
> Matt Didcoe
> [email protected]
>
>
> On Sat, Jan 10, 2009 at 4:54 AM, sohdubom <[email protected]> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to