I have two models and a join table, User
, Post
and posts_users
.
The posts_users
table contains a few extra fields, one of which is is_active
. I want to set all of a users posts to active providing the user is active themselves.
I have the following
$this->Post->PostsUser->updateAll(array('PostsUser.is_active' => 1), array('PostsUser.user_id' => $data['User']['id'], 'User.is_active' => 1));
Which causes a MySQL error
Warning (512): SQL Error: 1054: Unknown column 'User.is_active' in 'where clause' ...
Query: UPDATE
posts_sites
ASPostsUser
SETPostsUser
.is_active
= 1 WHEREPostsUser
.user_id
= 1 ANDUser
.is_active
= 1
As you can see the User table isn't getting joined in the query. Is there away around this problem?