Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

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
[shmem]: LanX can get the logs from cbstream at any time from me.
shmem relocates to the pub over the street. Have a nice time.
[LanX]: well .. not so much interested in reading this article
[LanX]: my 2 cents: AngloZionistic sounds like an antisemtic theory, but to be critical of zionism doesn't mean to be anti-semitic
[shmem]: it hasn't been coined as a *mustread* without authority from the promoter
erix shoots an anti-bubble missile towards LanX
[LanX]: I don't have the time to go into depth of this blog though
[LanX]: anti-bubble missile?

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (10)
As of 2018-03-19 21:35 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (246 votes). Check out past polls.