Re: Objects tree with Class::DBI

[prev] [thread] [next] [Date index for 2005/05/13]

From: Michael Peters
Subject: Re: Objects tree with Class::DBI
Date: 12:03 on 13 May 2005
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)

Objects tree with Class::DBI
subscribes 19:57 on 12 May 2005

Re: Objects tree with Class::DBI
Perrin Harkins 20:31 on 12 May 2005

Re: Objects tree with Class::DBI
Christopher Hicks 21:14 on 12 May 2005

Re: Objects tree with Class::DBI
Jay Strauss 21:22 on 12 May 2005

Objects tree with Class::DBI
subscribes 03:38 on 13 May 2005

Re: Objects tree with Class::DBI
Michael Peters 12:03 on 13 May 2005

Generated at 16:36 on 28 Jul 2005 by mariachi v0.52