The benefits of OOP are mostly in information hiding. If you're creating a bunch of long inheritance chains, you're probably doing OOP poorly. Composition is preferred. And maps *much* more naturally onto a relational database.
On Thu, Jun 14, 2012 at 11:37 PM, Alex Erzin <eaa-h...@yandex.ru> wrote: > Hm... it really works, but where are benefits of OOP? ;) > There is no inheritance at all, and to access parent's properties I should > call parent directly, so inheritance just replaced with incapsulation, and > it's no one what i try to find. > > Some years ago we have implemented inheritance in ORM in some commercial > project in Perl, later I have swithed to java and have found Hibernate it > really cool with ORM. > But now I have returned to Perl and I think that DBIx::Class can help me with > ORM, but right now i'm confused that cannot find "standard" solution for > typical task. > > > 15.06.2012, 10:25, "Hailin Hu" <i...@h2l.name>: >> Is it acceptable like something below >> >> package Target; >> ... >> package Host; >> ... >> __PACKAGE__->belong_to('target' => 'Target', 'target_id'); >> sub column_only_exists_in_target { >> my $self = shift; >> return $self->target->column_only_exists_in_target; >> } >> >> well, it is not a good solution, but it could work, I think :) >> >> On Fri, Jun 15, 2012 at 3:04 PM, Alex Erzin <eaa-h...@yandex.ru> wrote: >> >>> 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@ >>> >>> _______________________________________________ >>> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class >>> IRC: irc.perl.org#dbix-class >>> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/ >>> Searchable Archive: >>> http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk >> >> _______________________________________________ >> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class >> IRC: irc.perl.org#dbix-class >> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/ >> Searchable Archive: >> http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk > > -- > eaa@ > > _______________________________________________ > List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class > IRC: irc.perl.org#dbix-class > SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/ > Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk _______________________________________________ List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class IRC: irc.perl.org#dbix-class SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/ Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk