On Jun 10, 3:12 pm, Dave Howell <[email protected]> wrote:
> From "Sequel::Model::Associations::ClassMethods --> associate, options"
>
> :select - the attributes to select. Defaults to the associated class‘s 
> table_name.* in a many_to_many association, which means it doesn't include 
> the attributes from the join table. If you want to include the join table 
> attributes, you can use this option . . .

It certainly sounds undisclosed. :)

> Yes, indeed, I *do* want to include a column from the join table. HOW??? I've 
> found about five different ways to NOT get a useful result from what I stick 
> after :select=>, but I cannot find any explanation or example of what *does* 
> work.

It works just like any other Dataset#select call, but for multiple
arguments you provide an array.  There's more detail in the
association basics guide: 
http://sequel.rubyforge.org/rdoc/files/doc/association_basics_rdoc.html.
To quote from it:

:select

The columns to SELECT when loading the association. For most
associations, it defaults to nil, so * is used. For many_to_many
associations, it defaults to the associated class’s table_name.*,
which means it doesn’t include the columns from the join table. This
is to prevent the common issue where the join table includes columns
with the same name as columns in the associated table, in which case
the joined table’s columns would usually end up clobbering the values
in the associated table. If you want to include the join table
attributes, you can use this option, but beware that the join table
columns can clash with columns from the associated table, so you
should alias any columns that have the same name in both the join
table and the associated table. Example:

  Artist.one_to_many :albums, :select=>[:id, :name]
  Album.many_to_many :tags, :select=>[:tags.*, :albums_tags__number]

Jeremy

-- 
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.

Reply via email to