Hi
I've been trying to set a tree association for a legacy schema, mainly
having all descendants.
But I never managed to get what I wanted, and I even noticed a simple
association was not working.
I tried with a very simplified model and database, basically having
(tsn, parent_tsn, name), tsn being the primary key.
It's not 'id' because it's a legacy schema.
Here's my code with the full database, which gives error :
require 'rubygems'
require 'sequel'
ITISDB = Sequel.sqlite('itis_legacy/itis.db')
class TaxonomicKingdom < Sequel::Model
self.db = ITISDB
set_primary_key :kingdom_id
set_dataset :kingdoms
end
class TaxonomicUnitType < Sequel::Model
self.db = ITISDB
set_primary_key [:kingdom_id, :rank_id]
alias :name :rank_name
def direct_parent
TaxonomicUnitType[self.kingdom_id, self.direct_parent_rank_id]
end
def required_parent
TaxonomicUnitType[self.kingdom_id, self.required_parent_rank_id]
end
end
class TaxonomicUnit < Sequel::Model
self.db = ITISDB
set_primary_key :tsn
many_to_one :parent, :key => :parent_tsn
one_to_many :children, :classname => TaxonomicUnit, :key
=> :parent_tsn
end
if __FILE__ == $0
initial_tu = TaxonomicUnit[202423]
initial_tu.children.each do |tu|
p tu.name1
end
end
and the error :
E:\base rage>ruby itis_legacy/itis.rb
c:/ruby/lib/ruby/gems/1.8/gems/sequel-2.4.0/lib/sequel_model/
inflector.rb:177:in `constantize': uninitialized constant Child
(NameError)
from c:/ruby/lib/ruby/gems/1.8/gems/sequel-2.4.0/lib/
sequel_model/association_reflection.rb:48:in `associated_class'
from c:/ruby/lib/ruby/gems/1.8/gems/sequel-2.4.0/lib/
sequel_model/associations.rb:370:in `_children_dataset'
from c:/ruby/lib/ruby/gems/1.8/gems/sequel-2.4.0/lib/
sequel_model/record.rb:354:in `send'
from c:/ruby/lib/ruby/gems/1.8/gems/sequel-2.4.0/lib/
sequel_model/record.rb:354:in `_dataset'
from c:/ruby/lib/ruby/gems/1.8/gems/sequel-2.4.0/lib/
sequel_model/associations.rb:267:in `children_dataset'
from c:/ruby/lib/ruby/gems/1.8/gems/sequel-2.4.0/lib/
sequel_model/record.rb:403:in `send'
from c:/ruby/lib/ruby/gems/1.8/gems/sequel-2.4.0/lib/
sequel_model/record.rb:403:in `load_associated_objects'
from c:/ruby/lib/ruby/gems/1.8/gems/sequel-2.4.0/lib/
sequel_model/associations.rb:268:in `children'
from itis_legacy/itis.rb:31
And my code with the simplified table, which works :
require 'rubygems'
require 'sequel'
DB = Sequel.sqlite('itis_legacy/test.db')
class TaxonomicUnit < Sequel::Model
set_primary_key :tsn
many_to_one :parent, :key => :parent_tsn
one_to_many :children, :class => TaxonomicUnit, :key => :parent_tsn
end
if __FILE__ == $0
initial_tu = TaxonomicUnit[1]
initial_tu.children.each do |tu|
p tu.name
end
end
I don't quite get why it errors on me with the full table, which has
all the 3 same columns, and a bunch more.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---