On Wednesday, October 31, 2012 9:25:26 AM UTC-7, 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 > > It'd be nice if you could just do: > class Fan < Sequel::Model > one_to_many :artists, :name => :fans > end > > This still takes advantage of inflection based configuration, but allows > you to control the resulting method names. I'm happy to submit a PR for > this, but Jeremy requested feedback from the community before he'd consider > the addition. >
Basically, I'm leaning against this, so unless I see broad community support for it, I don't plan on adding this feature. My main reason against adding it is that adds yet another option, for the sole purpose of making defining associations very slightly less verbose for many_to_one and many_to_many associations. Your contrived example doesn't make sense to me. For one_to_many associations, the :key option is not inferred from the association name, and would default to fan_id. If even a contrived example can't use the proposed feature correctly, is it really needed? IIRC, for one_to_many and one_to_one associations, the only option inferred from the association name is the :class option, so for those associations, a separate association option to set the base name makes no sense. For many_to_one associations, both :class and :key are inferred from the association name, so in that case you would be saving one option. For many_to_many, :class, :join_table, and :right_key are inferred from the association name, so you would only be saving two options there. Personally, I think it's better to explicitly specify both :class and :key for many_to_one and :class, :join_table, and :key for many_to_many than to add another option that overrides the base name used for the defaults for those options. Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/sequel-talk/-/5kDHkRbSvHwJ. 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.
