[Dbix-class] table-per-subclass - how it works?

Alex Erzin eaa-home at yandex.ru
Fri Jun 15 06:04:14 GMT 2012


Hello,

I need to implement table-per-class inheritance, as it simple made in Hibernate in Java (more details can be found here http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html/ch10.html#inheritance-tablepersubclass), 
but cannot find right way how to do it in DBIx::Class.

For example, I have two objects: Target (with properties ID, Description) and Host (ID, Hostname, IP), Host inherited from Target, and on table-level there are two tables Host and Target, joined by ID field.

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)?

Thanks.

-- 
eaa@



More information about the DBIx-Class mailing list