Я новичок в бэкэнд-разработке и застрял с простым запросом и прошу помощи.
Я пытаюсь получить простое соединение:
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;
}
Product_barcode
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)