On Jun 10, 2010, at 16:00 , Dave Howell wrote:
>
> On Jun 10, 2010, at 15:34 , Jeremy Evans wrote:
>
>> Example:
>>
>>
>> Artist.one_to_many :albums, :select=>[:id, :name]
>> Album.many_to_many :tags, :select=>[:tags.*, :albums_tags__number]
>>
>> 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.
>
> Aha! I looked at the RDoc for "Dataset::Select" and based on that, tried
> putting an array of symbols in, but that failed.
Well, bother. It's STILL failing.
I've got three tables: batches, lnkbatchesingredients, and lstingredients. The
linking table has two foreign keys (batches_id and ingredients_id) and a column
called "percentage".
class Batch < Sequel::Model;
many_to_many :ingredients, :join_table=>:lnkbatchesingredients,
:select=>[:lnkbatchesingredients__percentage, :lstingredients.*];
end
>> b = Batch[:batch_id=>"34dbf102-2384-11df-9f0d-00065b3f562c"]
=> #<Batch @values={...blah blah blah values blah blah blah...}>
>> b.ingredients[1]
=> #<Ingredient @values={:name=>"Ethanol", :id=>1,
:ingredient_id=>"4ace3f92-2357-11df-966c-00065b3f562c",
:percentage=>#<BigDecimal:10012ff10,'0.9E0',4(12)>}>
>> b.ingredients[1].name
=> "Ethanol"
>> b.ingredients[1].ingredient_id
=> "4ace3f92-2357-11df-966c-00065b3f562c"
>> b.ingredients[1].percentage
NoMethodError: undefined method `percentage' for #<Ingredient:0x10012f218>
from (irb):95
from :0
So it's picking up the fields from the associated table no problem, but isn't
creating the accessor method for percentage. Huh?
--
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.