如何解决我必须在cakphp中包含两个具有json字段值的模型
log table with product id product table 我的日志表包含具有json数据之类的数据字段
{"product-id":"14","product-name":"test","product-url":"\/projects\/test\/products\/lecture-details\/8","product-type":"lecture","product-price":"0"}
我要加入产品表,并将产品ID存储在数据文件中。该怎么做?
日志表“ product-id”:“ 14”,该字段必须包含在产品表中。
$getQuery = $this->Log->find('all')->matching('Users',function ($q) { return $q->where(['Users.is_deleted' => 'n']);})->contain(['Users','Products'])->select(['user_id' => 'Users.id','username' => 'Users.username','fname' => 'Users.fname','lname' => 'Users.lname','email' => 'Users.email','view_date' => 'Log.dt_created_on','data' => 'Log.data'])->where($conditions);
解决方法
添加此代码日志关联模型
$this->hasOne('Products',[
'className' => 'Products','foreignKey' =>false,'conditions' => array("Products.id=JSON_VALUE(cast(log.data as nvarchar(256)),'$.\"product-id\"')")
]);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。