[Dbix-class] overriding create [was role of result class? ]

Matt S Trout dbix-class at trout.me.uk
Wed Mar 8 12:45:23 CET 2006


Richard Jolly wrote:
> I'm trying to override the create() method of a particular class, so
> that it creates two other related objects. But using the
> $schema->resultset('Foo')->create syntax bypasses my overriden method.
> Is that expected?
> 
> If I define new() instead it does get called - but since I'm inserting
> rows with create_related I think it needs to be in create. The method in
> question looks something like:
> 
> sub create {
>   my $row = shift()->next::method(@_);
>   $row->create_related(..);
>   $row
> }

Yep. And as noted in the docs, create() is just a shortcut to ->new(@_)->insert;

So maybe overriding insert would do the trick :)

-- 
      Matt S Trout       Offering custom development, consultancy and support
   Technical Director    contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +



More information about the Dbix-class mailing list