[英]Yii and Relational Queries
我有一些帶有外鍵引用的表:
User
-> Tech
-> TechSchedule
> Location
-> Customer
看來我可以一次使用以下查詢來獲取任何相關數據給用戶。 考慮以下查詢:
// load the user model
$model = User::model()->findByPk( Yii::app()->user->id );
// print
echo "<pre>", print_r( $model->attributes ), "</pre>";
// print more about the user
echo "<pre>", print_r( $model->Tech->TechSchedule[0]->Location->Customer ), "</pre>";
打印輸出
Array
(
[user_id] => 1
[username] => someusername
[password] => somepassword
[salt] => somesalt
)
Customer Object
(
[_new:CActiveRecord:private] =>
[_attributes:CActiveRecord:private] => Array
(
[customer_id] => 14
[more customer data...]
)
[_related:CActiveRecord:private] => Array
(
)
[_c:CActiveRecord:private] =>
[_pk:CActiveRecord:private] => 14
[_alias:CActiveRecord:private] => t
[_errors:CModel:private] => Array
(
)
[_validators:CModel:private] =>
[_scenario:CModel:private] => update
[_e:CComponent:private] =>
[_m:CComponent:private] =>
)`
這是正常行為嗎? 如果是這樣,那么解決編寫關系查詢的麻煩的目的是什么,例如
$model = User::model()->with('Tech.TechSchedule.Location.Customer')->findByPk( Yii::app()->user->id );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.