On Wednesday, October 31, 2012 6:33:32 PM UTC-7, Nels Nelson wrote: > I am encountering a weird problem. Object associations don't appear to be > getting loaded onto various objects when marshaled into entities from the > db. > > I have eager loading turned on for a particular model, which is also using > the rcte_tree plugin. > > These errors don't seem to happen when eager loading is turned off. > These errors also seem to go away when I make a naive little patch to the > appropriate source files. See below. > > Locations of apparent originations of problems are approximately in the > following spots. > > associations.rb: > 1113: def_many_to_many > 1167: object.associations[name].push(assoc_record)} > > 1273: def_one_to_many > 1328: object.associations[name].push(assoc_record) > > plugins/rcte_tree.rb: > 95: apply > 209: root.associations[ancestors] << obj > > 316: root.associations[descendants] << obj > > > My very naive patches to these files involve adding more or less this line > immediately preceding the above: > > object.associations[name] ||= [] > > > The full stack trace looks more or less like this: > > undefined method `<<' for nil:NilClass > /usr/local/lib/ruby/gems/shared/gems/sequel-3.39.0/lib/sequel/plugins/rcte_tree.rb:316:in > > `apply' > /usr/local/lib/ruby/gems/shared/gems/sequel-3.39.0/lib/sequel/dataset/actions.rb:57:in > > `all' > /usr/local/lib/ruby/gems/shared/gems/sequel-3.39.0/lib/sequel/plugins/rcte_tree.rb:296:in > > `apply' > /usr/local/lib/ruby/gems/shared/gems/sequel-3.39.0/lib/sequel/model/associations.rb:2081:in > > `eager_load' > /usr/local/lib/ruby/gems/shared/gems/sequel-3.39.0/lib/sequel/model/associations.rb:2044:in > > `eager_load' > /usr/local/lib/ruby/gems/shared/gems/sequel-3.39.0/lib/sequel/plugins/tactical_eager_loading.rb:47:in > > `load_associated_objects' > /usr/local/lib/ruby/gems/shared/gems/sequel-3.39.0/lib/sequel/model/associations.rb:1109:in > > `descendants' > > > Any chance you could come up with a self contained example showing the problem? The integration tests cover eager loading both ancestors and descendants, and are fairly extensive, so either this is a local problem or there is a weird corner case you are hitting that isn't tested by the specs.
Earlier in the custom eager loaders for rcte_tree, the root objects should have those associations set to [] (lines 169 and 268), so the << call should be called on an array, not nil. BTW, what ruby distribution are you using? I only ask because the traceback looks a bit strange (shared instead of 1.8 or 1.9.1). Thanks, Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/sequel-talk/-/-X3p8os_uwEJ. 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.
