Currently, models can have any possible dataset.  Almost all models use 
dataset that selects from a single table, but there are models that use a 
joined dataset. The most common case for model joined datasets is models 
using the class_table_inheritance plugin.

In most cases, it should not be necessary to use a joined dataset. 
 Instead, the joined dataset can be wrapped in a subquery, and the main 
query just selects from the subquery. For example, this model with a joined 
dataset:

  class Foo <  Sequel::Model(DB[:foos].join(:bars, 
:id=>:bar_id).select_all(:foos).select_append{bars[:name].as(:bar_name)})
    SELECT foos.*, bars.name FROM foos INNER JOIN bars ON (bars.id = 
foos.bar_id)
  end

can be changed to:

  class Foo <  Sequel::Model(DB[:foos].join(:bars, 
:id=>:bar_id).select_all(:foos).select_append{bars[:name].as(:bar_name)})
    SELECT * FROM (SELECT foos.*, bars.name FROM foos INNER JOIN bars ON 
(bars.id = foos.bar_id)) AS foos
  end

One advantage of this is that you can now use unqualified values when 
filtering:

  Foo.first(:id=>1)

I recently added support to the class_table_inheritance plugin for an 
:alias option that automatically uses a subquery in this manner.

Is there any user who uses joined datasets for models and would not be able 
to deal with wrapping them in a subquery as described above?  If so, please 
describe your situation and why wrapping in a subquery will not work, so I 
can decide whether that is something we want to support going forward.

Thanks,
Jeremy

-- 
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 https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to