On May 1, 1:40 am, jeremyz <[email protected]> wrote:
> The full backtrace is :
>
> class T1 < Sequel::Model
>     set_schema do
>         primary_key :id, :auto_increment => true
>         text :a1
>     end
>     one_to_many :tjoins
> end
> class Tjoin < Sequel::Model
>     set_schema do
>         foreign_key :t1_id, :table => :t1s, :null => false
>         text :ajoin, :null => false
>     end
>     many_to_one :t1
> end
> T1.create_table!
> Tjoin.create_table!
> t1 = T1.create( :a1 => 'A' )
> join1 = Tjoin.create( :t1_id=>t1.id, :ajoin=>'JOIN' )
> puts T1.eager_graph(:tjoins).where(:t1s__a1=>'A').select
> (:tjoins.*).all
>
> [info] SELECT `tjoins`.* FROM `t1s` LEFT OUTER JOIN `tjoins` ON
> (`tjoins`.`t1_id` = `t1s`.`id`) WHERE (`t1s`.`a1` = 'A')
> /var/lib/gems/1.9.1/gems/sequel-2.12.0/lib/sequel/model/
> associations.rb:1146:in `block in eager_graph_build_associations':
> undefined method `pk' for nil:NilClass (NoMethodError)
>         from /var/lib/gems/1.9.1/gems/sequel-2.12.0/lib/sequel/model/
> associations.rb:1144:in `each'
>         from /var/lib/gems/1.9.1/gems/sequel-2.12.0/lib/sequel/model/
> associations.rb:1144:in `eager_graph_build_associations'
>         from /var/lib/gems/1.9.1/gems/sequel-2.12.0/lib/sequel/model/
> associations.rb:1294:in `post_load'
>         from /var/lib/gems/1.9.1/gems/sequel-2.12.0/lib/sequel/dataset.rb:
> 125:in `all'
>         from sequel_test.rb:31:in `<main>'

This occurs because you are using eager_graph but you aren't selecting
any values from the original table.  That isn't allowed.  Try:

  Tjoin.join(:t1s, :id=>:t1_id).where(:t1s__a1=>'A').select
(:tjoins.*).all

The following doesn't work but probably should be fixed:

  Tjoin.eager_graph(:t1).where(:t1__a1=>'A').select(:tjoins.*).all

It doesn't work because Tjoin doesn't have a primary key, and the code
currently requires the table have one (though it doesn't require the
record to have a value for the primary key, because it supports
selecting records that don't include the primary key).

You probably shouldn't be eager_graphing if you don't want associated
records.  Since you are only selecting columns from one table, you
apparently don't want associated records.

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