Re: [CDBI] self-referential has_many possible with subclass?

[prev] [thread] [next] [Date index for 2005/08/14]

From: Charles Bailey
Subject: Re: [CDBI] self-referential has_many possible with subclass?
Date: 21:36 on 14 Aug 2005
On 8/12/05, Phil Mitchell <seasprocket@xxxxx.xxx> wrote:
> In MyApp::Page ...
> MyApp::Page->has_many( comments =3D> 'MyApp::Page::Comment );
>=20
> And in MyApp::Page::Comment...
> MyApp::Page::Comment->has_a( refers_to =3D> MyApp::Page );
>=20
> Comment is a subclass of Page.
>=20
> But the compiler dies with:
>=20
> Error:  Can't locate object method "meta_info" via package
> "MyApp::Page::Comment" at
> /usr/local/share/perl/5.8.4/Class/DBI/Relationship/HasMany.pm line 28,
> <DATA> line 22008.
>=20
> Is this just not possible?

It is possible, but you need to be careful about order of statements.=20
The problem here is likely is that CDBI's relationship innards try to
C<require> the target class's definition as the relationship is set
up.  In this case, a partially-set-ujp MyApp::Page tries to establish
a has_many relationship with MyApp::Page::Comment, which in turn tries
to require MyApp::Page again as it sets up the has_a.  This should
work as long as you're careful to say:

    package MyApp::Page;
    ...
    __PACKAGE__->has_many( comments =3D> 'MyApp::Page::Comment');
    ...
    1;

    package My:App::Page::Comment;
    ...
    1;
    ...=20
    MyApp::Page::Comment->has_a( refers_to =3D> 'MyApp::Page');

In other words, let MyApp::Page call out to MyApp::Page::Comment, but
defer setting up the "reverse" relationship until both classes have
otherwise finished initializing themselves.


--=20
Regards,
Charles Bailey
Lists: bailey _dot_ charles _at_ gmail _dot_ com
Other: bailey _at_ newman _dot_ upenn _dot_ edu

_______________________________________________
ClassDBI mailing list
ClassDBI@xxxxx.xxxxxxxxxxxxxxxx.xxx
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi

Re: [CDBI] self-referential has_many possible with subclass?
Charles Bailey 21:36 on 14 Aug 2005

Generated at 13:17 on 19 Aug 2005 by mariachi v0.52