[Dbix-class] table-per-subclass - how it works?
Darius Jokilehto
darius.jokilehto at net-a-porter.com
Fri Jun 15 13:29:46 GMT 2012
On 15/06/12 07:04, Alex Erzin wrote:
> Hello,
>
[ ... ]
> CREATE TABLE `mydb`.`target` (
> `target_id` INT NOT NULL ,
> `description` VARCHAR(45) NULL ,
> PRIMARY KEY (`target_id`) )
>
> CREATE TABLE `mydb`.`host` (
> `target_id` INT NOT NULL ,
> `hostname` VARCHAR(45) NULL ,
> `ip` VARCHAR(45) NULL ,
> PRIMARY KEY (`target_id`) ,
> CONSTRAINT `fk_host_target`
> FOREIGN KEY (`target_id` )
> REFERENCES `mydb`.`target` (`target_id` )
> )
>
> How to implemeng there classes Target and Host, so it possible to write
>
> print $target->id(), $targer->description()
> print $host->id(), $host->description(), $host->hostname(), $host->ip()
>
> ?
>
> I have no ideas how to implement inheritance, and all my experiments are failed - from Host i cannot get access to parent properties like description.
> Could you help me please (with examples)?
I don't know how you'd get $host->id (maybe you meant
$host->target_id?), but you can proxy accessors across to other table
definitions by specifying them in your relationship definition (see the
'proxy' section under
https://metacpan.org/module/DBIx::Class::ResultSource#add_relationship).
Darius
NET-A-PORTER.COM
Irresistible fashion at your fingertips
CONFIDENTIALITY NOTICE
The information in this email is confidential and is intended solely for the addressee. Access to this email by anyone else is unauthorised. If you are not the intended recipient, you must not read, use or disseminate the information. Any views expressed in this message are those of the individual sender, except where the sender specifically states them to be the views of Net-A-Porter Group Limited.
The Net-A-Porter Group Limited is a company registered in England & Wales Number: 3820604 Registered Office: 1 The Village Offices, Westfield, Ariel Way, London, W12 7GF
More information about the DBIx-Class
mailing list