[Dbix-class] update and join

Lasse Makholm lasse at unity3d.com
Wed Nov 19 14:26:06 GMT 2014


On Tue, Nov 18, 2014 at 12:50 PM, Peter Rabbitson <rabbit+dbic at rabbit.us>
wrote:

> On 11/18/2014 12:36 PM, RAPPAZ Francois wrote:
>
>> Thanks for replying !
>>
>> So it's a feature, not a bug ?
>>
>
> It's neither, it has to do with design.
>
>  In mysql, I can execute
>> "update `ddrefs` inner join `ddusers` using (iduser) set id_credit = 22
>> WHERE ddrefs.iduser = 3"
>>
>
> A similar (though *not* identical) effect can be achieved by operating on
> a ResultSet (not Result). Given your original example, the above would look
> something like:
>
> $s->resultset('Ddref')->search(
>   { 'RefUser.iduser' => 3 },
>   { join => 'RefUser' }
> )->update({ id_credit => 22 });
>
> Again - you need to internalize the difference between the Result and
> ResultSet concepts, they are not interchangeable (if anything - they are
> orthogonal).


What really made it "click" for me was realizing that I should think of a
ResultSet, not primarily as a collection of rows, but rather as an SQL
query under construction (that might eventually get executed by calling
->first, ->next, ->all, etc...).

In reality, of course, ResultSets behave as both, but the part about it
being a query-in-the-making is a subtle yet profound aspect that enables
all sorts of interesting design patterns.

It took me too long to realize this when I started out with DBIC - probably
because our code base made almost no use of it...

/L


>
> _______________________________________________
> 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 at lists.scsys.co.uk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20141119/3e0e01b2/attachment.htm>


More information about the DBIx-Class mailing list