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.tirv...@gmail.com> 
wrote:
 

 On Sat, Aug 19, 2017 at 12:07 AM, Thomas Sibley <trsib...@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.ne...@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.

   
_______________________________________________
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@lists.scsys.co.uk

Reply via email to