David A. Black wrote in post #712598:
> Hi --
>
> On Wed, 6 Aug 2008, Shawn .. wrote:
>
>
> The has/belongs semantics are, indeed, not always a perfect fit for
> the way things relate when we describe them in English. For example, I
> remember coming up with an example once where I ended up with a Club
> belonging to a Member (or something like that; I'm not remembering
> exactly), whereas normally we'd say "He belongs to that club."
>
> My advice would be to use it as is for a while. If you want two-way
> has_many's, then just use has_many. Remember that the main point of
> associations, in any case, is that they generate methods for you. It's
> nice to have them as close as possible to the domain you're modeling,
> but it's often not very close since "has" and "belongs to" are not
> general terms for expressing every possible connection between two
> things.
>
> In the end, I think it's better to keep the number of association
> methods down, partly because it helps when it comes to learning how
> the associations themselves behave -- which ones trigger automatic
> saves, and when, and things like that.
>
>
> David

I am very grateful for this response. I, too was having a bit of 
difficulty earlier when the "English just wasn't making sense". See, I 
have an Event model and a DressCode model and I want to say that Event 
has_one DressCode, but I put the foreign key (dress_code_id) in the 
Event model (just as I would in my usual SQL/PHP ways. It turned out 
that I had to say DressCode has_many Events and Event belongs_to 
DressCode. Unorthodox but it works because now I can run 
Event.dress_code and I get the result i'm looking for.

Rails is so advanced that I sometimes forget that it is still just a 
programming language and, as you said, can't always be semantically 
correct all the time when illustrating real world relationships.

I spent a while searching, ended up on this thread and I finally got my 
head around it. To the original poster - just take the advice and do 
what needs to be done in order to satisfy the rails convention. Reading 
your code might be weird, but that's nothing that a few comments can't 
fix ;)

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to