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

Richard Jolly Richard.Jolly at bbc.co.uk
Wed Mar 8 19:24:15 CET 2006


Matt S Trout wrote:
> 
> 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 :)

It wouldn't work for my situation, as I want to divvy the arguments
given to create between a couple of other classes. By the time insert
was called it would have died with a 'no such column' error.

However I decided that giving it a name other than create would be a
good idea. But I'm still confused about where it should be defined and
how it should be called. 

package My::Schema::Artist;

sub make_things { }

...

$schema->resultset('Artist')->make_things(...)  # not found
$schema->class('Artist')->make_things(...)      # found

Is the second syntax somehow violating the Schema Way? 

I'll also be looking at custom resultsets for complex searches, but
that's presumably a different situation.

Thanks again, 

Richard



> -- 
>       Matt S Trout       Offering custom development, 

http://www.bbc.co.uk/

This e-mail (and any attachments) is confidential and may contain
personal views which are not the views of the BBC unless specifically
stated.
If you have received it in error, please delete it from your system. 
Do not use, copy or disclose the information in any way nor act in
reliance on it and notify the sender immediately. Please note that the
BBC monitors e-mails sent or received. 
Further communication will signify your consent to this.





More information about the Dbix-class mailing list