Duplicate where clause for deleted_at column
I have User_model and Email_model where users can have more than one email but an email can be assigned to only one user. All primary keys for my tables are id. Both models has timestamps and soft deletes.
# At User_model.php
$this->has_many['emails'] = array(
'foreign_model'=>'Email_model',
'foreign_table'=>'v_emails',
'foreign_key'=>'user_id',
'local_key'=>'id'
);
# At Email_model.php
$this->has_one['user'] = array('User_model', 'id' , 'user_id' );
When I run $this->email_model->with_user()->get(19), two sql queries are running. First is OK but second it has duplicate where clause for deleted_at column.
# First One OK.
SELECT *, `user_id` FROM `v_emails`
WHERE v_emails.deleted_at IS NULL AND `v_emails`.`id` = 19
LIMIT 1
# SECOND - PROBLEMATIC ONE
SELECT * FROM `v_users`
WHERE v_users.deleted_at IS NULL
AND `v_users`.`id` IN('10')
AND v_users.deleted_at IS NULL
Am I doing something wrong or Model is producing duplicate deleted_at IS NULL.
Thanks for any help.
If It would help to find out,
When I run $email = $this->email_model->where('email', '[email protected]')->get();,
This also return duplicate WHERE v_emails.deleted_at IS NULL
But when I run this $email = $this->email_model->get(['email'=>'[email protected]']);, this returns SINGLE WHERE v_emails.deleted_at IS NULL
You are not doing any thing wrong. it is a minor issue in MY_Model. The issue does not affect the end result. I am working on a fix for this. Hopefully I will have it tested be next week.