Hi,

I have a very simple case with two tables, users and tickets, where
tickets.reporter is a foreign key on users.id.  I figure this would be
modelled with a many_to_one relationship:

require 'rubygems'
require 'sequel'

Sequel.sqlite("tickets.sqlite") do |DB|

        DB.create_table! :users do
                primary_key :id
                String :username
        end

        DB.create_table! :tickets do
                primary_key :id
                foreign_key :reporter, :users # References users.username
                String :title
        end

        class User < Sequel::Model(:users); end
        class Ticket < Sequel::Model(:tickets); end

        Ticket.many_to_one :reporter, :key=>:reporter, :class=>User

        DB[:users].insert(:username=>'joe')
        DB[:tickets].insert(:reporter=>1, :title=>"Joe's issue")

        puts Ticket[1].reporter
end

However this code blows up with:

/var/lib/gems/1.8/gems/sequel-3.8.0/lib/sequel/model/associations.rb:
713:in `reporter': stack level too deep (SystemStackError)
        from /var/lib/gems/1.8/gems/sequel-3.8.0/lib/sequel/model/
associations.rb:169:in `send'
        from /var/lib/gems/1.8/gems/sequel-3.8.0/lib/sequel/model/
associations.rb:169:in `can_have_associated_objects?'
        from /var/lib/gems/1.8/gems/sequel-3.8.0/lib/sequel/model/base.rb:
393:in `any?'
        from /var/lib/gems/1.8/gems/sequel-3.8.0/lib/sequel/model/
associations.rb:169:in `each'
        from /var/lib/gems/1.8/gems/sequel-3.8.0/lib/sequel/model/
associations.rb:169:in `any?'
        from /var/lib/gems/1.8/gems/sequel-3.8.0/lib/sequel/model/
associations.rb:169:in `can_have_associated_objects?'
        from /var/lib/gems/1.8/gems/sequel-3.8.0/lib/sequel/model/
associations.rb:976:in `_load_associated_objects'
        from /var/lib/gems/1.8/gems/sequel-3.8.0/lib/sequel/model/
associations.rb:1029:in `load_associated_objects'
         ... 3441 levels...
        from /var/lib/gems/1.8/gems/sequel-3.8.0/lib/sequel/core.rb:100:in
`connect'
        from /var/lib/gems/1.8/gems/sequel-3.8.0/lib/sequel/core.rb:237:in
`adapter_method'
        from /var/lib/gems/1.8/gems/sequel-3.8.0/lib/sequel/core.rb:244:in
`sqlite'
        from test.rb:4

It seems the problem is that I use the Symbol :reporter both as the
table column name (which I can't change, unfortunately) and as the
name of the Ticket field. If I change:
        Ticket.many_to_one :reporter, :key=>:reporter, :class=>User
to:
        Ticket.many_to_one :myreporter, :key=>:reporter, :class=>User
then this works:
        puts Ticket[1].myreporter

Could this be considered a bug? Or am I doing something stupid?


Thanks,
Jeff
-- 
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