ppgengler@prevailhs.com wrote in post #968602:
> On Dec 14, 10:14am, Marnen Laibow-Koser <li...@ruby-forum.com> wrote:
>>
>> Hold it. If there's a habtm relationship between Person and Address,
>> then Addresses shouldn't even have a person_id. OTOH, if there isn't a
>> habtm relationship, then the << operation is unnecessary (and I think
>> it's a syntax error).
>>
>> So...which is it?
>
> In his original example Address has a person_id field so I was
> assuming a has_many relationship, not a HABTM.
Which means << is invalid, doesn't it?
> However, though I'd
> want to reflect on it further, I'm pretty sure it doesn't change
> anything here as long as you deal with the relationship name
> everywhere and not the ID fields; Rails will just do The Right Thing
> (tm) and add/remove records in the join table appropriately.
It's has_many, so there's no join table.
[...]
> I think maybe what you're pointing out though, is that he could just
> do:
>
> @address = Factory(:address)
>
> and then use @address.person?
>
No. That's not at all what I'm pointing out.
> If that's adequate then that's definitely cleaner (and quicker and
> more robust). However, what I read from the OP is that he has a need
> to create a Person object first, configured a specific way (although
> he didn't have any particular factory overrides, so maybe this is an
> incorrect assumption?). ~After~ that object is created he needs an
> Address that is linked to it. As such he either needs to 1) create
> the Address object with a stub Person, then associate with the one he
> wants afterwards (suboptimal, the usage of <<) or 2) pass in the
> Person object to the Address factory to link at creation time
> (preferred, AFAIK).
That's correct.
Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
>
> \Peter
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No comments:
Post a Comment