Colin Law wrote in post #1052973: > On 23 March 2012 16:48, bingo bob <[email protected]> wrote: >> >>>> Freddy (2, male) >>> >>> What if one of the Freddys is female? Maybe not likely with this name >>> but there are names that can be both. >> >> True - in my system the user simply designates a name as either M or F, >> gender is an attribute of name...quite possible to have the same name as >> both M and F and rightly so, actually current schema attached in case it >> helps. > > I think you would be better to have a join table, user_names maybe. > Then have > User > has_many :user_names > has_many :names, :through => :user_names > > UserName > belongs_to :user > belongs_to :name > > Name > has_many :user_names > has_many :users, :through => :user_names > > Have given and gender in names and the position in user_names > > I think that might help a lot. For example to find how many users > have a name you can then just use @name.users.count. > > Colin
Thanks for taking the time Colin, that's thought provoking in several ways. 1) You're right the ability to do simply @name.users.count would be excellent. 2) I've got an existing schema in place and am wondering if I can migrate to this new schema (perhaps with some additional migrations and rake tasks) or maybe that's a very tricky task. 3) Linked to two, think carefully about the data model before starting out. I don't think what I've got is wrong it's just that @name.users.count and the like seems like the most elegant way to handle the queries I need to be doing. The idea of a join table scares me a bit but I get where you're coming from. -- 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 [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.

