[Dbix-class] inheritance
Hermida, Leandro
Leandro.Hermida at fmi.ch
Wed Sep 13 15:54:27 CEST 2006
Thank you for the reply,
Is there any way in the class definition to specify a default prefetch
attribute? Otherwise in every place in the application where I do the
resultset search method on a concrete class I think I will have to put
the entire inheritance tree for that particular class, $attrs = {
prefetch => { 'parent_class' => { 'parent_of_parent_class' =>
'parent_of_parent_of_parent_class' } } }.
Leandro
Matt S Trout wrote:
> Create classes for them anyway, then have something like (in
TreatmentProtocol)
>
> __PACKAGE__->might_have('_protocol', 'My::Schema::Protocol', undef, {
proxy =>
> [ qw/compound .../ ] });
>
> then you can do $treatment_protocol->compound and it'll Just Work
(though
> you'll need to specify the prefetch for _protocol to make it a single
query).
>
> Hermida, Leandro wrote:
> > Hello,
> >
> > I have a question about inheritance (or
generalization/specialization
> > hierarchies?) when building your classes using DBIx::Class. If I
have a
> > data model with inheritance:
> >
> > -- abstract class
> > create table parameterizable (
> > id INT NOT NULL
> > ... some basic columns here...
> > );
> >
> > -- abstract class
> > create table protocol (
> > id INT NOT NULL,
> > name VARCHAR(200)
> > );
> >
> >
> > create table growth_protocol (
> > id INT NOT NULL,
> > medium VARCHAR(200),
> > temperature VARCHAR(200)
> > );
> >
> > create table treatment_protocol (
> > id INT NOT NULL,
> > compound VARCHAR(200),
> > delivery_method VARCHAR(200)
> > );
> >
> >
> > alter table parameterizable
> > ADD CONSTRAINT pk_id_01 PRIMARY KEY (id)
> > ;
> >
> > alter table protocol
> > ADD CONSTRAINT pk_id_02 PRIMARY KEY (id)
> > ADD CONSTRAINT fk_id_02 FOREIGN KEY (id) REFERENCES
parameterizable (id)
> > ;
> >
> > alter table growth_protocol
> > ADD CONSTRAINT pk_id_03 PRIMARY KEY (id)
> > ADD CONSTRAINT fk_id_03 FOREIGN KEY (id) REFERENCES protocol (id)
> > ;
> >
> > alter table treatment_protocol
> > ADD CONSTRAINT pk_id_04 PRIMARY KEY (id)
> > ADD CONSTRAINT fk_id_04 FOREIGN KEY (id) REFERENCES protocol (id)
> > ;
> >
> > How does one represent this using DBIx::Class? Since abstract
classes
> > like Parameterizable and Protocol should never get instantiated
directly
> > then how do I create DBIx::Class packages for GrowthProtocol and
> > TreatmentProtocol which will transparently join with the to the
abstract
> > class tables and get the accessors when instantiating objects?
More information about the Dbix-class
mailing list