Re: Objects tree with Class::DBI
[prev]
[thread]
[next]
[Date index for 2005/05/13]
subscribes@xxxxxxxx.xx wrote:
> __PACKAGE__->has_many(children => ['PXF::M::Section' => 'parent']);
> I expect something like that
> [{
> id => 5,
> parent => undef,
> path => 'test',
> name => 'Section',
> children => [{
> id => 6,
> parent => {
> id => 5,
> parent => undef,
> path => 'test',
> name => 'Section'
> },
> path => 'test',
> name => 'Section'
> }]
> },
> {
> id => 6,
> parent => {
> id => 5,
> parent => undef,
> path => 'test',
> name => 'Section'
> },
> path => 'test',
> name => 'Section'
> children => []
> }
> ]
>
> but I retrieve following list (printed with Data::Dump)
> do {
> my $a = bless({
> id => 5,
> name => "Section",
> parent => bless({ id => 0 }, "PXF::M::Section"),
> path => "test",
> }, "PXF::M::Section");
> (
> $a,
> bless({ id => 6, name => "Section 2", parent => $a, path => "test2" }, "PXF::M::Section"),
> );
> }
> where is the children?
has_many() will create a method named children, not an array of the
children. It's lazy this way so that it doesn't have to get the children
from the database until you ask for it.
Does that make sense?
--
Michael Peters
Developer
Plus Three, LP
|
(message missing)
|