[Dbix-class] Scalar ref update()'s

Jose Fonseca zefonseca at gmail.com
Fri May 16 19:03:47 BST 2008


>...instance, I might want to set a column to \'NOW()' and have repeated,
>future updates bump the timestamp without having to explicitly set the
>timestamp column each time.

I'm not sure I follow. The problem is with reading back the value, not
writing. Also to bump the timestamp you need a round trip to the DB.

>So, reading the value from the DB should only be done at the user's
>request.  An update_and_refresh might be handy, but it's really not

Yep, totally agree. After giving it some thought too I think it oughta be
separated, though documented.

>necessary.  Since update returns $self, you could just:
> $row->update->discard_changes;

I propose then this gets documented on some future revision, because
discard_changes does not sound like something that would refresh new values.

Regards.

On Fri, May 16, 2008 at 2:41 PM, Marc Mims <marc at questright.com> wrote:

> * Jose Fonseca <zefonseca at gmail.com> [080516 10:30]:
> > A technical solution would involve what Ash called "too much magic", and
> I
> > sort of agree**. Also keeping it in 2 functions would keep the system
> well
> > decoupled instead of bloating it up(TMM again).
> >
> > [snip]
> >
> > ** The reason I don't agree completely is that, as explained above,
> > returning the scalar ref does not make any sense at all in update(). In
> my
> > opinion if we create a 2nd function, we should throw an immediate
> exception
> > when update is used with a scalar ref value to force it to break early
> and
> > let the developer know it's being used incorrectly. In my case I just
> wrote
> > that code assuming I'd get the date back because that scalar ref has
> nothing
> > to be doing in my Perl code.
>
> Having given it some thought, I completely agree that it's too much
> magic.  It may, in fact, be undesirable in some circumstances.  For
> instance, I might want to set a column to \'NOW()' and have repeated,
> future updates bump the timestamp without having to explicitly set the
> timestamp column each time.
>
> So, reading the value from the DB should only be done at the user's
> request.  An update_and_refresh might be handy, but it's really not
> necessary.  Since update returns $self, you could just:
>
>    $row->update->discard_changes;
>
>        -Marc
>
> _______________________________________________
> 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.rawmode.org
>



-- =

http://zefonseca.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20080516/b33=
5d98b/attachment-0001.htm


More information about the DBIx-Class mailing list