Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

with 关联,主表无法指定字段 #208

Open
zhouyouth opened this issue Aug 18, 2021 · 7 comments
Open

with 关联,主表无法指定字段 #208

zhouyouth opened this issue Aug 18, 2021 · 7 comments

Comments

@zhouyouth
Copy link

easyswoole框架版本号、orm组件版本号 [Version]

easyswoole 3.4.5 , orm 1.4
$res = ClientDataAccountModel::create()
->alias('dataAccount')
->field('dataAccount.id')
->with('account_users')
->all(['id' => $account_id]);
//关联模型
return $this->belongsToMany(OrganizationUserModel::class, "sk_client_data_account_users",'data_account_id','data_database_uid',function($query){
$query->fields("id,organization_id,account,status,name,phone,username");
});
}

报错如下
Unknown column 'data_account_id' in 'field list' [SELECT dataAccount.id, data_account_id FROM sk_client_data_account AS dataAccount WHERE id = 1

经过排查是
abstractModel
960 行
if (!in_array($pk, $this->fields) && $this->supplyPk == true){
$this->fields[] = $pk;
}
这里的问题

排查情况和最小复现脚本 [Tests and Recurrence]

@Marber-seven
Copy link

我也遇到和你一样的问题

@Marber-seven
Copy link

CREATE TABLE fa_goods (
id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'id',
title VARCHAR(100) NOT NULL DEFAULT '' COMMENT '名称',
sub_title VARCHAR(50) NOT NULL DEFAULT '' COMMENT '简介',
img VARCHAR(355) NOT NULL DEFAULT '' COMMENT '图片',
content TEXT COMMENT '商品详情',
status TINYINT(1) NOT NULL DEFAULT '1' COMMENT '状态?1:正常,0:下架',
is_delete TINYINT(1) NOT NULL DEFAULT '0' COMMENT '是否删除?1:是,0:否',
delete_time INT(11) NOT NULL DEFAULT '0' COMMENT '删除时间',
create_time INT(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
update_time INT(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
PRIMARY KEY (id)
) ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='商品表'

CREATE TABLE fa_goods_category (
goods_id INT(11) NOT NULL DEFAULT '0' COMMENT '商品id',
category_id INT(11) NOT NULL DEFAULT '0' COMMENT '分类id'
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 COMMENT='商品分类表'

CREATE TABLE fa_goods_tag (
goods_id INT(11) NOT NULL DEFAULT '0' COMMENT '商品id',
tag_id INT(11) NOT NULL DEFAULT '0' COMMENT '标签id'
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 COMMENT='商品标签表'

CREATE TABLE fa_group_goods (
id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'id',
goods_id INT(11) NOT NULL DEFAULT '0' COMMENT '商品id',
create_time INT(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
update_time INT(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
member_num INT(11) NOT NULL DEFAULT '0' COMMENT '人数',
username VARCHAR(50) NOT NULL DEFAULT '' COMMENT '微信',
poster_img VARCHAR(255) NOT NULL DEFAULT '' COMMENT '分海报图',
join_code VARCHAR(50) NOT NULL DEFAULT '' COMMENT '进群码',
PRIMARY KEY (id)
) ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='社群商品表'

商品模型类

class Goods extends AbstractModel
{
/**
* 获取分类
*/
public function category()
{
return $this->hasMany(GoodsCategory::class, function (QueryBuilder $query) {
}, "id", "goods_id");
}

/**
 * 获取标签
 */
public function tag()
{
    return $this->hasMany(GoodsTag::class, function (QueryBuilder $query) {
    }, "id", "goods_id");
}

}

调用方法

$list = (new Goods())->alias("goods")->field("*")
->getOrderBy(["goods.id"=>"desc"])
->withTotalCount()
->with(["tag","category"])
->join("fa_group_goods as group_goods", "goods.id = group_goods.goods_id", "inner")
->page(1,20)
->all(["goods.status"=>1]);

@XueSiLf
Copy link
Contributor

XueSiLf commented Aug 27, 2021

好的,感谢反馈,马上处理。

@Marber-seven
Copy link

好的,感谢反馈,马上处理。

好的,感谢

@XueSiLf
Copy link
Contributor

XueSiLf commented Aug 27, 2021

好的,感谢反馈,马上处理。

好的,感谢

你好,方便提供下数据吗?

@XueSiLf
Copy link
Contributor

XueSiLf commented Aug 27, 2021

easyswoole框架版本号、orm组件版本号 [Version]

easyswoole 3.4.5 , orm 1.4
$res = ClientDataAccountModel::create()
->alias('dataAccount')
->field('dataAccount.id')
->with('account_users')
->all(['id' => $account_id]);
//关联模型
return $this->belongsToMany(OrganizationUserModel::class, "sk_client_data_account_users",'data_account_id','data_database_uid',function($query){
$query->fields("id,organization_id,account,status,name,phone,username");
});
}

报错如下
Unknown column 'data_account_id' in 'field list' [SELECT dataAccount.id, data_account_id FROM sk_client_data_account AS dataAccount WHERE id = 1

经过排查是
abstractModel
960 行
if (!in_array($pk, $this->fields) && $this->supplyPk == true){
$this->fields[] = $pk;
}
这里的问题

排查情况和最小复现脚本 [Tests and Recurrence]

你好,请问方便提供一条测试数据及表结构,用于debug吗?

@Marber-seven
Copy link

好的,感谢反馈,马上处理。

好的,感谢

你好,方便提供下数据吗?

INSERT INTO fa_goods(title,sub_title,img,content,is_delete,delete_time,create_time,update_time,)
VALUES ('资源社群1','好资源','','

32234234234

',0,0,1629950001,1630056931);

INSERT INTO fa_goods_tag(goods_id,tag_id) VALUES (1,4),(1,3);

INSERT INTO fa_goods_category(goods_id,category_id) VALUES (1,4),(1,3);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants