On 25 août, 21:32, Brad <[EMAIL PROTECTED]> wrote:
> I think you just need to change :classname to :class and things might
> work. In your working example you typed things correctly, which is
> probably why you didn't get the error.
>
> Hope this helps,
> Brad
Thanks, that was it. I triple checked, but I missed it anyway.
So, now that the direct children are working, back to the original
problem I had : descendants.
here's the dump of my test database (simplified version of the legacy
schema):
BEGIN TRANSACTION;
CREATE TABLE "taxonomic_units" (
"tsn" INTEGER PRIMARY KEY NOT NULL,
"parent_tsn" INTEGER NOT NULL,
"name" TEXT
);
INSERT INTO "taxonomic_units" VALUES(1,'','1');
INSERT INTO "taxonomic_units" VALUES(2,1,'1:1');
INSERT INTO "taxonomic_units" VALUES(3,1,'1:2');
INSERT INTO "taxonomic_units" VALUES(4,2,'1:1:1');
COMMIT;
Here's the code :
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
many_to_one :descendants, :class => TaxonomicUnit, :eager_loader =>
( proc do |key_hash, nodes, associations|
id_map = {}
nodes.each do |n|
n.associations[:children] = []
id_map[n.pk] = n
end
TaxonomicUnit.filter(:parent_tsn =>
id_map.keys).eager(:descendants).all do |node|
parent = id_map[node.parent_tsn]
node.associations[:parent] = parent
parent.associations[:children] << node
end
end)
end
if __FILE__ == $0
tsn = 1
puts "********** Children"
TaxonomicUnit[tsn].children.each do |tu|
p tu.name
end
puts "********** Descendants"
TaxonomicUnit.filter(:tsn => tsn).eager(:descendants).all do |tu|
p tu.name
end
end
and the output, which puzzles me :
E:\base rage>ruby itis_legacy\test.rb
********** Children
"1:1"
"1:2"
********** Descendants
"1"
I've tried one_to_many also, but it doesn't change anything.
Any lights on this ?
regards
Maz
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---