My problem is in using addInCondition for searching.
I’m using “many to many” relations models in addInCondition, and it return me object, where isset only seted values in addInCondition, but i want to find with other values of setted value.
For example
table user
id…name
1…John
2…Mary
table user_to_country
user_id…country_id
1…1
1…3
2…2
2…1
table country
id…country_name
1…United Kingdom
2…Ukraine
3…Afganistan
If i set :
$criteria->addInCondition(‘country_id’, $value); // $value = 1 for example
In result :
John {country : United Kingdom} // i want to get country : United Kingdom, Afganistan
Mary {country : United Kingdom} // i want to get country : United Kingdom, Ukraine
May the problem in aliases of tables, which i add by method “with”, 'cause in addInCondition i’m using field name of “many to many” table but not target table named “country” in this example.
Thank you in advance (and i’m know english not so good)
yes, i’m set related models in “with” - problem is not in retrieve any data, i retrieve base (central) model with data, which match to set in addInCondition values, for example if base model in relation has values “1”,“2” and in addInCondition will set only “1”, in result i’m retrieving base (central) model without related value “2” 'cause it does not match to condition, but i want to retrieve FULL model, now i’m twice call findAll and findByPk, in first set my custom conditions and secondary in find i retrieve full model by pk
How about getting country ids from center table by searching user ids? If you use findAll for John (1) you will get country ids 1 & 3. If you have set BELONGS_TO in your model relation you can esaily get the country name rt?
there should be relation in your user_to_country model
$userCountry = UserToCountry::model()->findAllByAttributes(array('user_id'=>$uid));
if(!empty($userCountry)){
foreach($userCountry as $uCountry){
//here you can get the country name by using $uCountry->countryR->country_name
}
}