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

Justin Guenther jguenther at gmail.com
Wed Mar 8 21:40:42 CET 2006


On 3/8/06, Richard Jolly <Richard.Jolly at bbc.co.uk> wrote:
> 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.

I had a very similar problem. I created my own ResultSet class,
overriding new_result() and create(). The new_result() method calls
$self->result_source->result_class->new(@_) and sets the new object's
resultsource to $self->result_source. Create() simply returns
$self->new_result(@_)->insert().

Then, I overrode new() and insert() in my Schema classes, catching the
extra args and dealing with them manually.

Hope that helps... I can post some example code later if you want, I
have a meeting to go to or I would now.

> 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.
>
>
>
> _______________________________________________
> List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
> Wiki: http://dbix-class.shadowcatsystems.co.uk/
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
>



More information about the Dbix-class mailing list