[Dbix-class] find_or_create did it find or created?

Rajeev Prasad rp.neuli at yahoo.com
Mon Aug 21 00:45:06 GMT 2017


hi Triveni ji,I have not encountered the 'race cond.' yet in various scripts. (but) if you explain to me how to break find and replace into a transaction. I would consider that. I am not very good at DBIx, i just happen to use it.Thank you.Rajeev
 

    On Sunday, August 20, 2017 6:08 AM, tirveni yadav <yadav.tirveni at gmail.com> wrote:
 

 On Sat, Aug 19, 2017 at 12:07 AM, Thomas Sibley <trsibley at uw.edu> wrote:
> Use find_or_new instead, and then check $id->in_storage.  Make sure to call
> $id->insert when $id->in_storage is false.
>
> This is explained in the documentation for find_or_create, starting with “If
> you need to know if an existing row was found or a new one created…”.
>
>
> On Aug 18, 2017, at 10:34 , Rajeev Prasad <rp.neuli at yahoo.com> wrote:
>
> How do we know wether this function 'found' or created whatever was being
> asked to 'find_or_create' ???
>
> my $id = $schema
>        ->resultset('Node')
>        ->find_or_create
>        (
>            { nodeName => $node },
>            { key => 'nodeID' }
>        );
> how do we know wether $id was already existing in table?


I would suggest that you avoid find_or_create, unless you know what
are you are doing.
find_or_create is subject to Race condition as well.

Hence, best to do it inside a transaction.

Or keep it simple and do a find and then create inside a transaction.


-- 
Regards,

Tirveni Yadav

www.bael.io

What is this Universe ? From what it arises ? Into what does it go?
In freedom it arises, In freedom it rests and into freedom it melts away.
Upanishads.

   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20170821/3c6a3003/attachment.htm>


More information about the DBIx-Class mailing list