On Jun 10, 5:44 pm, Dave Howell <[email protected]> wrote:
> 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?

That's expected behavior.  percentage isn't an attribute of
Ingredient, so there isn't an accessor method created (Sequel doesn't
implement Model#method_missing).  You can either create an accessor
method yourself or use b.ingredients[1][:percentage] to access the
percentage.

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