[Dbix-class] Row updates with parameters vs. without
Ian
dbix-class at iandocherty.com
Wed Apr 7 22:14:27 GMT 2010
Here's another thought.
If you mistakenly did the following.
my $row = $schema->resultset('MyTable')->search({
col => 'some value',
});
Rather than
my $row = $schema->resultset('MyTable')->search({
col => 'some value',
})->first;
Then your
$row->update({attr => 'stuff', foo => 'bar', ultimate_answer => 42});
Would apply the update not to one row (as intended) but the entire
resultset.
Wheras
$row->attr('stuff');
$row->foo('bar');
$row->ultimate_answer(42);
$row->update;
Would give you a runtime error
Can't locate object method "attr" via package "DBIx::Class::ResultSet"
This might be more desirable than silently updating multiple (all?)
records in your database!
Regards
Ian
On 07/04/2010 22:47, Nathaniel Green wrote:
> Thanks for the response, Caleb. You do make a good point about readability.
>
> The best justification I could come up with was that using the
> accessors encapsulates the object better, allowing you to later change
> the underlying implementation without having to change update calls.
> But that seems a rare case.
>
> Any other thoughts?
>
> Thanks,
> Nate
>
>
> On Wed, Apr 7, 2010 at 3:45 PM, Caleb Cushing<xenoterracide at gmail.com> wrote:
>> On Tue, Apr 6, 2010 at 12:46 PM, Nathaniel Green<nate.green at gmail.com> wrote:
>>> $row->update({ attr => 'stuff', foo => 'bar', ultimate_answer => 42 });
>>>
>>
>> There may be another reason but the latter is more readable... however
>>
>> $row->update({
>> attr => 'stuff',
>> foo => 'bar',
>> ultimate_answer => 42,
>> });
>>
>> that isn't less readable and it's as easy as the other to update.
>> where your one liner makes it a little bit harder to see changes if
>> you change it... and you need to diff the change.
>>
>> just my 2 cents. probably more justification for the other way elsewhere.
>> --
>> Caleb Cushing
>>
>> http://xenoterracide.blogspot.com
>>
>> _______________________________________________
>> 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
>
>
More information about the DBIx-Class
mailing list