[Dbix-class] Inheritance not preserved when using compose_namespace

Scott Thomson smoothhound at gmail.com
Tue Sep 25 09:28:47 GMT 2007

On 9/24/07, Matt S Trout <dbix-class at trout.me.uk> wrote:
> On Mon, Sep 24, 2007 at 03:11:28PM +0100, Scott Thomson wrote:
> > Hi All,
> >
> > I posted a version of this problem on the catalyst list but I now
> > think it's more DBIC related so excuse the cross-post :-)
> >
> > I have a setup similar to this...
> >
> > Class B inherits from class A and class C has a relationship to A.
> > A and B share the same table and I use the dynamic sub-classing
> > approach in the cookbook to get the sub-classing to work.
> >
> > When testing directly with the schema the classes behave as I would
> > expect, ie. I can set the value of the relationship on C using an
> > object of class either A or B. However, when I use the schema inside
> > my Catalyst app I get an error like this when trying to set the
> > property using the relationship on A to an object of the sub-class
> > C...
> >
> > DBIx::Class::MyApp::new(): Object
> > MyApp::Model::DBIC::A::B=3DHASH(0x392b6a0) isn't a MyAPP::Model::DBIC::A
> > (The error is generated in
> > DBIx::Class::Relationship::Base::set_from_related)
> >
> > It seems that the B isa A relationship is not preserved within the
> > MyApp::Model namespace.  After some digging around it seems like it is
> > the call to compose_namespace in Catalyst::Model::DBIC::Schema::new
> > that is causing this behaviour.  Effectively it renames all the schema
> > classes into the MyApp::Model namespace and the ISA chain in the new
> > namespace is not preserved, so this would affect any schema that is
> > generated using the compose_namespace method.
> >
> > I'm a bit stumped on how to proceed, I can get round the problem with
> > a bit of a hack (basically by not using the relationship to set
> > values) but I'm converting a large set of classes to DBIC and this
> > problem is going to occur in quite a few places.
> >
> > Given the ubiquity of DBIC as a model for Catalyst I'm quite surprised
> > that no-one has come up against this before - which may mean that it's
> > something that I'm doing wrong  :-)
> No, that's a bug.
> I guess compose_namespace should look for classes its composing in the
> inheritance tree and swap 'em for the composed version.
> Anybody up for having a go at a test+patch?

A test I can have a stab at (see attached), however I think a patch is
beyond me!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: XXcompose_namespace.t
Type: application/x-troff
Size: 1005 bytes
Desc: not available
Url : http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20070925/fc=

More information about the DBIx-Class mailing list