I have free tables: user, book, user_book, offers
user table has method:
public function getBooks()
{
return $this->hasMany(UserBook::className(), ['user_id' => 'id']);
}
user_book table has two fields: user_id, book_id; and methods
public function getUser()
{
return $this->hasOne(User::className(), ['id' => 'user_id']);
}
public function getBook()
{
return $this->hasOne(Book::className(), ['id' => 'book_id']);
}
table offer have method like: getUser(), getBook(),
and now I would like show Books which user don't have. I try do something like
$query = Offer::find()
->with('user')
->andWhere([
'offer.status' => Offer::STATUS_ACTIVE,
]);
$query->andWhere(['not in', 'offer.book_id', 'user.books.book_id']);
but it doesn't work. Do you have some ideas how can I make it?