Rows

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Rows

Erik Colson
Hello,

How can I check if the contents of 2 Row Objects are identical ?
I'm used to create a function to check the individual fields, but maybe
DBIx::Class is smarter on this ?

Thanks
--
erik

_______________________________________________
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@...
Reply | Threaded
Open this post in threaded view
|

Re: Rows

Patrick Meidl
On Fri, Jul 27 2012, Erik Colson <[hidden email]> wrote:

> How can I check if the contents of 2 Row Objects are identical ?  I'm
> used to create a function to check the individual fields, but maybe
> DBIx::Class is smarter on this ?

in ORM, identity is usually defined by having the same primary key. if
you maniplulate your objects after fetching them from the database,
though, you will have to do dirty checking (i.e. check if any columns
were changed in the detached object). you can use e.g. $row->is_changed
for this, see

http://search.cpan.org/~frew/DBIx-Class-0.08198/lib/DBIx/Class/Row.pm#is_changed

HTH

    patrick

--
Patrick Meidl ........................ [hidden email]
Vienna, Austria ...................... http://gplus.to/pmeidl


_______________________________________________
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@...
Reply | Threaded
Open this post in threaded view
|

Re: Rows

Erik Colson
Patrick Meidl <[hidden email]> writes:

> On Fri, Jul 27 2012, Erik Colson <[hidden email]> wrote:
>
>> How can I check if the contents of 2 Row Objects are identical ?  I'm
>> used to create a function to check the individual fields, but maybe
>> DBIx::Class is smarter on this ?
>
> in ORM, identity is usually defined by having the same primary key. if
> you maniplulate your objects after fetching them from the database,
> though, you will have to do dirty checking (i.e. check if any columns
> were changed in the detached object). you can use e.g. $row->is_changed
> for this, see
>
> http://search.cpan.org/~frew/DBIx-Class-0.08198/lib/DBIx/Class/Row.pm#is_changed
>
> HTH
>
>     patrick

Hi Patrick,

That is one thing I want to check.. Thank you for the link !

I also ant to now if somenone else did change anything in the row as
saved in the database. I can achieve this by adding a serial field which
increases at every update, but hence, maybe DBIx::Class has something
for this too ;)

--
erik

_______________________________________________
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@...
Reply | Threaded
Open this post in threaded view
|

Re: Rows

Ian Docherty (icydee)
On 27 July 2012 14:48, Erik Colson <[hidden email]> wrote:

> Patrick Meidl <[hidden email]> writes:
>
>> On Fri, Jul 27 2012, Erik Colson <[hidden email]> wrote:
>>
>>> How can I check if the contents of 2 Row Objects are identical ?  I'm
>>> used to create a function to check the individual fields, but maybe
>>> DBIx::Class is smarter on this ?
>>
>> in ORM, identity is usually defined by having the same primary key. if
>> you maniplulate your objects after fetching them from the database,
>> though, you will have to do dirty checking (i.e. check if any columns
>> were changed in the detached object). you can use e.g. $row->is_changed
>> for this, see
>>
>> http://search.cpan.org/~frew/DBIx-Class-0.08198/lib/DBIx/Class/Row.pm#is_changed
>>
>> HTH
>>
>>     patrick
>
> Hi Patrick,
>
> That is one thing I want to check.. Thank you for the link !
>
> I also ant to now if somenone else did change anything in the row as
> saved in the database. I can achieve this by adding a serial field which
> increases at every update, but hence, maybe DBIx::Class has something
> for this too ;)
>
> --
> erik
You just need to read a bit further down that same link :)

You can either use
http://search.cpan.org/~frew/DBIx-Class-0.08198/lib/DBIx/Class/Row.pm#get_from_storage
to get a fresh copy which you can compare with the one you have, or
alternatively, just call 'discard_changes' to reselect
the current object from the database and get the latest version.

Regards
Ian

_______________________________________________
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@...
Reply | Threaded
Open this post in threaded view
|

a function as a column

Erik Colson
In reply to this post by Patrick Meidl
Hi all,

I have a table with numeric fields a en b. So the Resultsource declaration is

  __PACKAGE__->add_columns( 'a' => { is_numeric => 1 },
                            'b' => { is_numeric => 1 }, )

In the Resultsource class I want to add sub c as follows:

  sub c {
    my $self = shift;
    return $self->a + $self->b
  }

Now how can I use c as a column ? This is what I need:

  my $selection = $rs->search({}, { columns => [qw /a b c/] }) ;

which would return a,b,c for all rows in the table, keeping the function
c hidden behind the name of a column.

Any hints ?
--
erik colson

_______________________________________________
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@...