Cakephp: Make Table::findOrCreate null-safe

Created on 9 Dec 2016  路  3Comments  路  Source: cakephp/cakephp

This is a (multiple allowed):

  • [x] bug
  • [x] enhancement
  • [ ] feature-discussion (RFC)

  • CakePHP Version: 3.x

  • Platform and Target:

What you did

I tried to use the Table::findOrCreate method with properties that may contain null values.

What happened

Since the properties ($search) are passed to the Query::where method directly, this is not null-safe. The where method translates this to `property_name = null`.

What you expected to happen

It would be nice to have a null-safe function here.

Since CakePHP has the Automatic IS NULL Creation, we simply could append an ' is' to all keys of the search array before passing it to the Query::where method.

If this enhancement is accepted, I could create a pull request for it.

defect enhancement

Most helpful comment

findOrCreate also uses the search query to bootstrap the entity, but that might not be an issue.

I would rather loop the search key/value pairs and create query expressions. That opens the door to support IN if a value is an array.

All 3 comments

findOrCreate also uses the search query to bootstrap the entity, but that might not be an issue.

I would rather loop the search key/value pairs and create query expressions. That opens the door to support IN if a value is an array.

Good Idea @thinkingmedia, I will create a pull request soon.

Closing as a pull request is open.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jorisvaesen picture jorisvaesen  路  3Comments

josbeir picture josbeir  路  3Comments

lorenzo picture lorenzo  路  4Comments

saeideng picture saeideng  路  3Comments

micdobro picture micdobro  路  3Comments