On Sat, Jan 14, 2012 at 14:20, bingo bob <[email protected]> wrote:

> I'm doing it wrong aren't I ! ?

Not necessarily.  If it's OK for your purposes, that two people named
Harry have their names being two different objects, your model (as I
understand it, which may be incorrectly) is perfectly fine.

> I need to do habtm - find it scary tbh, never used it in anger.

Don't worry about habtm.  Taken from your followup message:

On Sat, Jan 14, 2012 at 14:21, bingo bob <[email protected]> wrote:

> How do I setup the habtm relationships I need an additional table right?

Under the hood, yes, but it happens automagically so you don't need to
be concerned with that.

*BUT*....

You may want to consider hmt (has_many :through) instead.  I've heard
habtm disparaged many times by people who couldn't get it to work, so
maybe the magic there is a bit unreliable.  (Never had a problem with
it myself, though.  Maybe there's a Heisenbug?)

The other, more "real", problem with habtm is that it's apparently
very difficult to retrofit into hmt, if you ever discover a need to
keep any info about the relationship.  (Again, haven't run into that
problem myself, but due to lack of need, rather than having success.)
So, I tend to go with hmt to start with, even if it's only storing the
same stuff as habtm would (just the ids of the related objects).

Now, in hmt, you do need an additional table and model.  In your
setup, IF you wanted to have all people named Harry point at the same
"Harry" name object, maybe I'd call it something like "namings".
Initially this would contain just the ids of the person object and the
name object.  If you like, you can later use that same table to record
when the person was named, whether it's their first or middle name or
what, their preferred diminutive (perhaps as another name id), who
suggested naming the person that (as another person id), etc. etc.
etc.  Adding on more data like that will be much easier with hmt than
habtm.

-Dave

-- 
Dave Aronson, President, Dave Aronson Software Engineering and Training
Ruby on Rails Freelancing (Northern Virginia, Washington DC, or Remote)
DaveAronson.com, Codosaur.us, Dare2XL.com, & RecruitingRants.com (NEW!)
Specialization is for insects. (Heinlein) - Have Pun, Will Babble! (me)

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to