From: Christian Neukirchen Date: 2006-08-16T21:11:44+09:00 Subject: Re: Dr Nic’s Magic Models Dr Nic writes: > Xavier Noria wrote: >> On Aug 16, 2006, at 8:38 AM, Dr Nic wrote: >> >>> This might just be sacrifice of using the MMs. I'm not sure there's a >>> way to know to create just a HABTM when you might need a has_many >>> :through; the latter being more general and powerful. The triggering >>> logic would be the same. >> >> Couldn't you just create a habtm if there are no columns in the >> intermediate tale but the ones with the keys? Does MM support has_one >> BTW? > > It generates a has_one if your method name is singular. > > E.g. > > @person.membership - has_one > @person.memberships - has_many > > So much magic in one place! :) Whoa, ouch. :-P A very simple and trying-to-be-completely-unmagic-but-clever ORM I've been writing recently makes relationships based on foreign keys. If the field referenced is declared "unique", it will be like has_one, else like has_many. Of course, my system was made for non-legacy and well-specified database schemata. -- Christian Neukirchen http://chneukirchen.org