On Oct 31, 2012, at 9:25 , Tyler Kellen wrote: > It'd be nice if you could optionally define the name for methods created when > adding an association. > > Here is a contrived example: > > class Fan < Sequel::Model > one_to_many :artists > end > > Say you want to reference a fan's favorite artists as 'friends' instead of > 'artists', as in: Fan[:id=>1].friends instead of Fan[:id].artists. Right > now, the only way to do that is to use the first argument as the name and > explicitly define the rest of the association, like so: > > class Fan < Sequel::Model > one_to_many :friends, :class => :Artist, :key => :artist_id > end
Wait, each fan has many artist friends, but each artist has one fan? > It'd be nice if you could just do: > class Fan < Sequel::Model > one_to_many :artists, :name => :fans > end Huh? Okay, so was this supposed to be > class Fan < Sequel::Model > many_to_one :artists, :name => :friend > end ?? So does the database still have an artist_id foreign key toward artist.id, or is the database column called friend_id? Because I don't like either answer. If the former, then what happens if I want to do > class Fan < Sequel::Model > many_to_one :artists, :name => :friend > many_to_one :artists, :name => :obsession > end Presumably that breaks. However, if the database column is called friend_id and obsession_id, then the database structure is no longer self-evident, in which case, I think having to type a couple extra characters is quite justified. -- You received this message because you are subscribed to the Google Groups "sequel-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/sequel-talk?hl=en.
