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

Thomas Sibley trsibley at uw.edu
Fri Aug 18 18:37:06 GMT 2017


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 <https://metacpan.org/pod/DBIx::Class::ResultSet#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?
> _______________________________________________
> 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

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


More information about the DBIx-Class mailing list