enfield
enfield

Reputation: 841

Yii relation, array check to see if value exists

I am trying to create a if then statement to only display something if a value in a array exists.

Given two tables Address and Player I have the following relation

'displayAddress' => array(self::HAS_MANY, 'Address', 'PlayerId', 
                        'condition'=>array('IsHome=:home', 'IsWork=:wok'),
                        'params' => array(':hom'=>'Y', ':wok'=>'N')),

Now in a Player view I want to check to see if that player has any addresses where it is only their home and not their work.

I have tried setting a function for the array and checking doing isset in the view as well as in_array() and array_key_exists() but I haven't been able to solve it.

Upvotes: 1

Views: 1783

Answers (1)

Eirik Hoem
Eirik Hoem

Reputation: 1310

The relation you have should / will return only instances where IsHome=Y and IsWork=N. Does this work as expected? If not, try:

'displayAddress' => array(self::HAS_MANY, 'Address', 'PlayerId', 'condition'=>'IsHome=:home AND IsWork=:wok', 'params' => array(':hom'=>'Y', ':wok'=>'N')),

Upvotes: 2

Related Questions