Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

object identity in DBIx::Class

by morgon (Deacon)
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:

Hi,

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!

Comment on object identity in DBIx::Class
Download Code
Re: object identity in DBIx::Class
by spx2 (Chaplain) 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?

    C.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://759838]
Approved by Bloodnok
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2014-10-02 12:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (56 votes), past polls