Hi,

follow up on my previous post: I've now a piece of working code giving me
the subproducts for each instance of 'Product' (using a single Sequel model
'Product', 2 MSSQL views and 1 many_to_many association).

class Product < Sequel::Model
  set_dataset DB[:tbl_products].select(:product_id, :name)
  set_primary_key :product_id
  many_to_many :subproducts, :class=>self, :select =>
[:tbl_products__product_id, :name], :join_table=>:tbl_sub_products,
:left_key=>:product_id, :right_key=>:reference_product
end

I've been experimenting with eager and rcte_tree plugin. All I want is to
be able given a product ID to get an array of products, including this top
product and its 1st-level children. Next plans are to extract the whole
hierarchy (descendance) for scoping purposes.

Rcte_tree is out of scope now as it request to define parent as well and
request dedicated parent_id on the table (and this is a view, out of my
control as I'm not an admin and I am only reading out data).

With eager, all I tried gave no valid output... I'm sure some eager loading
is happening as each of the 3 following attempts get longer response time:

>> Product.where(:product_id=>82188).eager(:subproducts).all
=> [#<Product @values={:product_id=>82188, :name=>"********"}>]

>> Product.where(:product_id=>82188).eager(:subproducts=>:subproducts).all
=> [#<Product @values={:product_id=>82188, :name=>"********"}>]

>>
Product.where(:product_id=>82188).eager(:subproducts=>{:subproducts=>:subproducts}).all
=> [#<Product @values={:product_id=>82188, :name=>"********"}>]

I've masked some names for obvious reasons.

Any hint please? Thanks in advance.

-- 
Christian

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to