1

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.

2
  • What do you mean by "any addresses where it is only their home and not their work."? Do you want to check if the two addresses are different? Commented Feb 4, 2012 at 19:46
  • Just as is stated in the condition/params of the relation I defined. I want to return a value only if the Player has at least one address that is both Home-Yes and Work-No Commented Feb 4, 2012 at 22:49

1 Answer 1

2

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')),

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.