TP5 remote one-to-many association parameters how to fill in
葫芦娃平衡盘
葫芦娃平衡盘 2018-05-08 14:33:44
0
5
1870

Let’s start with the idea of ​​​​finding the shop_id in the goods table based on the goodsiD in order_goods, and then finding the name in the shop table based on the shop_id. The order_goods table is not related to the shop table
I imitate the writing in TP5
public function shop( )
{
          return $this->hasManyThrough('Shop','Goods','goods_id','shop_id','id')->setEagerlyType(0);
 }
hasManyThrough('Associated model name', 'Intermediate model name', 'Foreign key name', 'Intermediate model associated key name', 'Current model primary key name', ['Model alias definition']);
is the following I don’t know how to write the parameters. Can any experts give me some advice?

葫芦娃平衡盘
葫芦娃平衡盘

reply all(1)
PeterZhu

Please open trace and post the generated SQL statement

  • reply Sorry, teacher, I don't know how to open trace...
    葫芦娃平衡盘 author 2018-05-08 16:27:47
  • reply Please read the official manual thoroughly: https://www.kancloud.cn/manual/thinkphp5_1/354096
    天蓬老师 author 2018-05-08 16:56:40
  • reply 老师 找到了 [ SQL ] SHOW COLUMNS FROM `ant_auth_group_access` [ RunTime:0.002001s ] [ SQL ] SELECT `aga`.`uid`,`aga`.`group_id`,`ag`.`id`,`ag`.`pid`,`ag`.`name`,`ag`.`rules` FROM `ant_auth_group_access` `aga` LEFT JOIN `ant_auth_group` `ag` ON `aga`.`group_id`=`ag`.`id` WHERE ( aga.uid='1' and ag.status='normal' ) [ RunTime:0.002000s ] [ SQL ] SHOW COLUMNS FROM `ant_auth_rule` [ RunTime:0.003000s ] [ SQL ] SELECT `id`,`pid`,`condition`,`icon`,`name`,`title`,`ismenu` FROM `ant_auth_rule` WHERE `status` = 'normal' [ RunTime:0.003000s ] [ SQL ] SHOW COLUMNS FROM `ant_order_goods` [ RunTime:0.003000s ] [ SQL ] SELECT * FROM `ant_order_goods` WHERE `id` = 13 LIMIT 1 [ RunTime:0.001000s ] [ SQL ] SHOW COLUMNS FROM `ant_goods` [ RunTime:0.003000s ] [ SQL ] SHOW COLUMNS FROM `ant_shop` [ RunTime:0.003000s ] 他的意思是没有找到 ant_goods和ant_shop吗
    葫芦娃平衡盘 author 2018-05-08 17:23:10
  • reply I don't quite understand why it only takes 3 parameters. Because I correspond to a field (second) of the middle table based on the field of the main table (the first one), and then get a certain piece of data corresponding to the middle table and then take it. Another field (the third one) corresponds to the data ID of the last table (the fourth one), so I think there should be four fields. This leads to me not knowing which of the three parameters to fill in.
    葫芦娃平衡盘 author 2018-05-08 17:30:05
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template