Active Relation question..

Hello,

I've got 3 tables

table user with primary key userId

table books with primary key bookId

table userHasBook with primary key the 2 foreign keys userId and bookId. This table has also a boolean field named 'active' which is my main problem

I've created a relation in the books model

With a call like

I can get the books that a user has however my problem is that I want to get all books that a user has as long as the userHasBook.active field is 1 (true) …

Unfortunately I don't have a way to access the 'active' value. Is there a way

to filter the results and get only the ones with userHasBook.active=1 ?

I've tried it by adding in the relation a 'condition'=>'??.active=1' but it results to an error since the query replaces the ?? with the table users and I have a condition where 'users.active=1' and of course mysql says that there is no such column.

Any ideas please ??

The alias for the join table is: <relation name>_<table alias>

So in your case, if you are using 'books' as the alias for your books model, then the join table alias is "has_books".

thanks! I addedd an alias for my users table and then as you said the the 'condition' of <relation_name>_<table_alias>.active=1 worked fine…

(sorry for posting in the wrong section… after the submit I couldn't move the post)