You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently $_related is a private property and there is no public or protected method to get $_related without specifying a key. Either $_related needs to be made protected or there needs to be a getRelated function that returns all. Without either of those, a class extending ActiveRecord can not access all of $_related.
The text was updated successfully, but these errors were encountered:
Why do you need to access it? You can get all relation data via $model->relationName and populate data via $data->populateRelation('relationName', $data)
Currently, Json::Encode($user); will only output the database columns of the user table, because of the toArray method is limited. If one wanted to override the toArray method to include the $_related, they could not do so without specifically building a new array object that is manually populated like below:
public function toArray(){
$data = new Array();
$data = $this->attributes();
$data['users'] = $this->users;
return $data;
}
It would be nice to be able to do something like:
public function toArray(){
$data = new Array();
$data = $this->attributes();
$data = array_mrege($data, $this->_related);
return $data;
}
That way if I chose to do $user = User::find()->with('orders')->with('phone_numbers'); Both the orders and phone_numbers would be output in the json.
Yeah I see your point. What I also found to be nice would be when __isset() would consider relational data as set when loaded and not set when not loaded.
fixesyiisoft#842
- allows checking whether a relation has been populated
- getting a list of relation names that have been populated
- getting all populated relation data
todo:
- [] add phpdoc
Currently $_related is a private property and there is no public or protected method to get $_related without specifying a key. Either $_related needs to be made protected or there needs to be a getRelated function that returns all. Without either of those, a class extending ActiveRecord can not access all of $_related.
The text was updated successfully, but these errors were encountered: