On May 16, 12:30 am, Xavier Lange <[EMAIL PROTECTED]> wrote: > It looks like ARAI Shunichi found this bug as well. I was able to push > my way through and continue working but I have hit another dataset > problem. > > How can I use a polymorphic many_to_many relationship if Sequel::Model > wants to use the join model's name as quantifier in the where > statement? Both models are using STI.
I don't know if you can. I haven't tested it, nor do I plan to. I'd be willing to accept a patch that fixes it (assuming it didn't complicate things too much), but I have no plans to work on one myself, ever. > (ItemContainer is omitted but it's the parent table/class of Factor) > > class Factor < ItemContainer > dataset.set_model(:kind, Hash.new {|h, k| h[k] = k.constantize > rescue nil}) > set_dataset Sequel::Model.db[:item_containers].where{:kind == > 'Factor'} > end > > class Survey < Sequel::Model > dataset.set_model(:kind, Hash.new {|h, k| h[k] = k.constantize}) > set_dataset Sequel::Model.db[:surveys].where{:kind == 'Survey'} > > many_to_many :item_containers > > before_create do > created_at = Time.now > updated_at = Time.now > end > before_save do > updated_at = Time.now > self[:kind] = self.class.to_s > end > end > > class EvenDistributionSurvey < Survey > dataset.set_model(:kind, Hash.new {|h, k| h[k] = k.constantize}) > set_dataset Sequel::Model.db[:surveys].where{:kind == > 'EvenDistributionSurvey'} > > many_to_many :item_containers > end > > >> f = Factor.create > > => #<Factor @values={:created_at=>Fri May 16 02:22:58 -0500 > 2008, :kind=>"Factor", :updated_at=>Fri May 16 01:32:33 -0500 > 2008, :title=>"", :id=>4}>>> eds = EvenDistributionSurvey.create > > => #<EvenDistributionSurvey @values={:created_at=>Fri May 16 02:23:11 > -0500 2008, :kind=>"EvenDistributionSurvey", :updated_at=>Fri May 16 > 01:32:33 -0500 > 2008, :items_per_factor=>nil, :title=>"", :code=>"", :id=>10}>>> f.add_survey > eds > > => #<EvenDistributionSurvey @values={:created_at=>Fri May 16 02:23:11 > -0500 2008, :kind=>"EvenDistributionSurvey", :updated_at=>Fri May 16 > 01:32:33 -0500 > 2008, :items_per_factor=>nil, :title=>"", :code=>"", :id=>10}>>> s = > Survey.create > > => #<Survey @values={:created_at=>Fri May 16 02:23:54 -0500 > 2008, :kind=>"Survey", :updated_at=>Fri May 16 01:32:33 -0500 > 2008, :items_per_factor=>nil, :title=>"", :code=>"", :id=>11}>>> f.add_survey > s > > => #<Survey @values={:created_at=>Fri May 16 02:23:54 -0500 > 2008, :kind=>"Survey", :updated_at=>Fri May 16 01:32:33 -0500 > 2008, :items_per_factor=>nil, :title=>"", :code=>"", :id=>11}> > > so the first error is that it's not casting the ItemContainer to a > Factor.>> s.item_containers > > => [#<ItemContainer @values={:created_at=>Fri May 16 02:22:58 -0500 > 2008, :kind=>"Factor", :updated_at=>Fri May 16 01:32:33 -0500 > 2008, :title=>"", :id=>4}>] > > and then when accessing from the EvenDistributionSurvey instance I get > a bad table look up>> eds.item_containers > > Mysql::Error: Table > 'survey_development.even_distribution_surveys_item_containers' doesn't > exist > > Any ideas on how I can whip this into shape? Don't use STI? Jeremy --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sequel-talk" group. To post to this group, send email to sequel-talk@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---