in the defaultScope, but that gives me a “Column not found: 1054 Unknown column ‘board.locale’ in ‘where clause’.” and might break other parts of the code where I’m loading the records without each other.
I read I have to set the alias property but I can’t seem to figure out how.
I’m sure it’s a simple solution but I can’t get it to work on my own. Your help is highly appreciated!
Hmm, it now broke my code in another part of my application: Unknown column ‘t.locale’ in ‘where clause’.
Problem lies here now:
FROM `transaction` `transaction` WHERE (t.locale='de')
It seems there’s a difference when doing eager and lazy loading? (the first one was eager loading, this is now lazy loading). What can I do about this?
The solution i found is to define the alias in the defaultScope definition. And that’s seems good (just coded it an hour ago, but all unit tests are ok).
public function defaultScope() {
return array( 'condition' => $this->tableName().'.active=1',
'alias' => $this->tableName()
);
I used $this->tableName(), because that default scope is defined in a base class which my models use but you can set a string instead.
The only thing that change now is that you have to use the tableName (or the string you choose) and not the relation name when writing condition on related models.