我是后端开发中的新手,并且坚持一个简单的请求并寻求帮助。 我正在尝试进行简单的加入:
select * from product a, product_barcode b
where a.productid = b.productid
课程结构:
产品
class Product extends ManagedObject<product> implements product {}
class product {
@primaryKey
int productid;
String rusname;
String engname;
ManagedSet<Product_barcode> products;
}
产品条形码
Class Product_barcode extends ManagedObject<product_barcode>
implements product_barcode {}
class product_barcode {
@primaryKey
int productid;
String barcode;
@Relate(#products)
Product product;
}
请求
@Operation.get()
Future<Response> getProducts() async {
final productQuery = Query<Product>(context)..join(set: (a) => a.products);
final res = await productQuery.fetch();
return Response.ok(res);
}
我提出请求时遇到错误:
SELECT t0.productid,t0.rusname,t0.engname,t1.productid,t1.barcode,t1.product_productid FROM product t0 LEFT OUTER JOIN product_barcode t1 ON t0.productid=t1.product_productid
column t1.product_productid does not exist
我做错了什么?我的数据库中没有列 product_productid
更新 表格结构
drugs=# \dt product_barcode
List of relations
Schema | Name | Type | Owner
--------+-----------------+-------+----------
public | product_barcode | table | druguser
(1 row)
drugs=# \d product_barcode
Table "public.product_barcode"
Column | Type | Collation | Nullable | Default
-----------+-------------------+-----------+----------+---------
productid | integer | | not null |
barcode | character varying | | not null |
Indexes:
"product_barcode_pk" PRIMARY KEY, btree (productid, barcode)
drugs=# \dt product
List of relations
Schema | Name | Type | Owner
--------+---------+-------+----------
public | product | table | druguser
(1 row)
drugs=# \d product
Table "public.product"
Column | Type | Collation | Nullable | Default
-------------------------+--------+-----------+----------+---------
productid | bigint | | not null |
rusname | text | | |
engname | text | | |
registrationdate | text | | |
dateofcloseregistration | text | | |
registrationnumber | text | | |
composition | text | | |
zipinfo | text | | |
producttypecode | text | | |
marketstatusid | text | | |
Indexes:
"product_pkey" PRIMARY KEY, btree (productid)