Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

object identity in DBIx::Class

by morgon (Curate)
on Apr 24, 2009 at 13:25 UTC ( #759838=perlquestion: print w/replies, xml ) Need Help??
morgon has asked for the wisdom of the Perl Monks concerning the following question:


I have a question about DBIx::Class.

Assume I have a resultset with moniker 'Hubba' and I do the following:

my $h1 = $schema->resultset('Hubba')->find(1); my $h2 = $schema->resultset('Hubba')->find(1);
So retrieving twice the same row with primary key 1 I get two different instances describing the same physical row.

Is there a way to use DBIx::Class in such a way that I would get back the same instance in case as above?

Many thanks!

Replies are listed 'Best First'.
Re: object identity in DBIx::Class
by spx2 (Deacon) on Apr 24, 2009 at 14:50 UTC
    Yeah,sub-class DBIx::Class and cache the objects it gives you with a expiry time of your choice,and define the 'time' as you want(maybe number of calls to ->find or maybe time in the usual sense),then you'll probably have the desired effect which may or may not be what you want,for alot of queries that cache may become kind of heavy on your memory usage. I'm looking forward to knowing if there's any built-in feature for DBIx::Class that does this.
      Caching is not what the OP asked for. It's more like the object uniqueness feature that Class::DBI had. No idea if DBIx::Class supports something similar.

        he wants the exact same results to be returned on a second call to ->find. what he didn't envision is a scenario where you have multiple processes writing in the db and ->find with the same arguments could return a totally different thing,so what he wants isn't very "thread-safe"(although ironically Perl has no usable threads from what I was told on multiple occasions).

        if he has just one process writing on the db then you're right,he could just switch to Class::DBI,and read this.

Re: object identity in DBIx::Class
by castaway (Parson) on Apr 25, 2009 at 21:36 UTC

    How about this one?.

    You didn't say why you needed that though, I'm curious, why?


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://759838]
Approved by Bloodnok
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2018-05-27 05:38 GMT
Find Nodes?
    Voting Booth?