Welcome Guest, Not a member yet? Register   Sign In
Why does $userModel->find(null) return all rows like $userModel->findAll()
#1

(This post was last modified: 03-20-2021, 04:46 AM by sba.)

Let's say I have a table with users (id, firstname) and a table with pets (id, id_user, species, petname) and one model each representing the tables.
Now I query all users owning a cat:

$this->userModel = new UserModel();
$this->petModel  = new PetModel();

$cat_owner = $this->userModel->find(
    $this->petModel->where('species', 'cat')->findColumn('id_user')
);


There are cat owners - find() returns rows of all users owning a cat.

But no one holds an Iguana:
$iguana_owner = $this->userModel->find(
    $this->petModel->where('species', 'iguana')->findColumn('id_user')
);


Incorrectly, now we receive all users because $this->petModel->where('species', 'iguana')->findColumn('id_user') returns null and find() acts like findAll()

I know, the query could also be written using join or otherwise... but I don't understand why find(null) returns all rows, whats the idea behind it?

Or am I misunderstanding something about the models, what is the best practice?
Reply


Messages In This Thread
Why does $userModel->find(null) return all rows like $userModel->findAll() - by sba - 03-20-2021, 03:31 AM



Theme © iAndrew 2016 - Forum software by © MyBB