[Dbix-class] Self-Reference table configuration issue
Hill, Woodrow J
woodrow.j.hill at bankofamerica.com
Wed Oct 18 18:33:56 CEST 2006
Greetings,
I'm in the process of converting over to DBIx::Class from
Class::DBI, and having issues with a setup that I have functional in the
latter. I have two tables in the database, one a "cross-reference" to
the other table, which references itself to define a hierarchical
structure. I'm having some issues adjusting the "many-to-many"
documentation to query such a setup correctly. The fundamental error is
that, when I call on an item that's supposed to be higher or lower in
the hierarchy, I get back my originating item.
My setup, trimmed down for public posting purposes, is very similar to
this:
[CrossReference table]
CrossRefID
HigherInformation (foreign key for SelfReference item higher in
hierarchy)
LowerInformation (foreign key for SelfReference item lower in hierarchy)
[SelfReference table]
InformationID
InformationTitle
[CrossReference.pm : Module for cross-reference table]
[...]
__PACKAGE__->belongs_to(HigherInformation =>
'Project::SelfReference');
__PACKAGE__->belongs_to(LowerInformation =>
'Project::SelfReference', 'LowerInformation');
[SelfReference.pm : Module for self-referenced table]
[...]
__PACKAGE__->has_many(higher_xref => 'Project::CrossReference',
'HigherInformation');
__PACKAGE__->has_many(lower_xref => 'Project::CrossReference',
'LowerInformation');
__PACKAGE__->many_to_many(higher_info => 'higher_xref',
'HigherInformation');
__PACKAGE__->many_to_many(lower_info => 'lower_xref',
'LowerInformation');
[From my test code]
[...set up Schema connection...]
my $test_information_item =
$schema->resultset('Information')->find(750);
is($test_information_item->lower_info->next->InformationID, '3542'); #
comes out as 750
As I mentioned, the Class::DBI equivalent I created works OK, if slowly
-- indeed, early benchmarking of simpler queries was a major reason I've
attempted this changeover. In the hope that I'm just missing a bit of
basic setup logic from DBIx::Class, as opposed to a syntactical error,
I've posted the above; if people want/need to see complete code, please
let me know.
Thank you, in advance, for your aid,
----Woodrow
More information about the Dbix-class
mailing list