表positionContent
Box-sizing: border-Box; border-top: rgb(238,238) 1px solid; vertical-align: top; border-bottom: rgb(238,238) 1px solid; padding-bottom: 8px; padding-top: 8px; padding-left: 8px; border-left: rgb(238,238) 1px solid; line-height: 20px; padding-right: 8px">id | Box-sizing: border-Box; border-top: rgb(238,238) 1px solid; line-height: 20px; padding-right: 8px">position_id | Box-sizing: border-Box; border-top: rgb(238,238) 1px solid; line-height: 20px; padding-right: 8px">content_title | Box-sizing: border-Box; border-top: rgb(238,238) 1px solid; line-height: 20px; padding-right: 8px">content_id | Box-sizing: border-Box; border-top: rgb(238,238) 1px solid; line-height: 20px; padding-right: 8px">is_recommend | Box-sizing: border-Box; border-top: rgb(238,238) 1px solid; line-height: 20px; padding-right: 8px">list_sort | Box-sizing: border-Box; border-top: rgb(238,238) 1px solid; line-height: 20px; padding-right: 8px">update_time | Box-sizing: border-Box; border-top: rgb(238,238) 1px solid; line-height: 20px; padding-right: 8px">create_time |
---|---|---|---|---|---|---|---|
Box-sizing: border-Box; border-top: rgb(238,238) 1px solid; line-height: 20px; padding-right: 8px">10 | Box-sizing: border-Box; border-top: rgb(238,238) 1px solid; line-height: 20px; padding-right: 8px">14Box-sizing: border-Box; border-top: rgb(238,238) 1px solid; line-height: 20px; padding-right: 8px">大成成长Box-sizing: border-Box; border-top: rgb(238,238) 1px solid; line-height: 20px; padding-right: 8px">160910Box-sizing: border-Box; border-top: rgb(238,238) 1px solid; line-height: 20px; padding-right: 8px">1Box-sizing: border-Box; border-top: rgb(238,238) 1px solid; line-height: 20px; padding-right: 8px">2017-02-09 11:51:56Box-sizing: border-Box; border-top: rgb(238,238) 1px solid; line-height: 20px; padding-right: 8px">2017-02-09 11:51:56Box-sizing: border-Box">Box-sizing: border-Box; border-top: rgb(238,238) 1px solid; line-height: 20px; padding-right: 8px">11 | Box-sizing: border-Box; border-top: rgb(238,238) 1px solid; line-height: 20px; padding-right: 8px">15Box-sizing: border-Box; border-top: rgb(238,238) 1px solid; line-height: 20px; padding-right: 8px">创新成长Box-sizing: border-Box; border-top: rgb(238,238) 1px solid; line-height: 20px; padding-right: 8px">2017-02-09 11:52:08Box-sizing: border-Box; border-top: rgb(238,238) 1px solid; line-height: 20px; padding-right: 8px">2017-02-09 11:52:08
position表
Box-sizing: border-Box; border-top: rgb(238,238) 1px solid; line-height: 20px; padding-right: 8px">title | Box-sizing: border-Box; border-top: rgb(238,238) 1px solid; line-height: 20px; padding-right: 8px">type | Box-sizing: border-Box; border-top: rgb(238,238) 1px solid; line-height: 20px; padding-right: 8px">num | Box-sizing: border-Box; border-top: rgb(238,238) 1px solid; line-height: 20px; padding-right: 8px">remark | Box-sizing: border-Box; border-top: rgb(238,238) 1px solid; line-height: 20px; padding-right: 8px">列表推荐一Box-sizing: border-Box; border-top: rgb(238,238) 1px solid; line-height: 20px; padding-right: 8px">五星推荐Box-sizing: border-Box; border-top: rgb(238,238) 1px solid; line-height: 20px; padding-right: 8px">3Box-sizing: border-Box; border-top: rgb(238,238) 1px solid; line-height: 20px; padding-right: 8px">Box-sizing: border-Box; border-top: rgb(238,238) 1px solid; line-height: 20px; padding-right: 8px">2017-02-09 00:00:00Box-sizing: border-Box; border-top: rgb(238,238) 1px solid; line-height: 20px; padding-right: 8px">2017-02-09 00:00:00Box-sizing: border-Box"> | Box-sizing: border-Box; border-top: rgb(238,238) 1px solid; line-height: 20px; padding-right: 8px">列表推荐二 | Box-sizing: border-Box; border-top: rgb(238,238) 1px solid; line-height: 20px; padding-right: 8px">热销基金Box-sizing: border-Box; border-top: rgb(238,238) 1px solid; line-height: 20px; padding-right: 8px">4Box-sizing: border-Box; border-top: rgb(238,238) 1px solid; line-height: 20px; padding-right: 8px">2017-02-09 00:00:00
---|
positionContent表的position_id对就position表的id。positionContent跟position是一对一的关系,反过来则是多对一。
model
hasOne(Position::className(),['id'=>'position_id']);
}
...
然后在Controller调用,这样就能拿到position表中的数据了。
position;
}
}
PHP;">
SELECT * FROM `position_content` WHERE `id`=10
SELECT * FROM `position` WHERE `id`='14'
以上所述是小编给大家介绍的Yii2中多表关联查询hasOne hasMany,希望对大家有所帮助。程序员遇到问题都会上(编程之家jb51.cc)查找问题解答方法!如果觉得站点还不错,随手转发给程序员朋友一下!
原文链接:https://www.f2er.com/php/17959.html