在Flutter中选择连接两个表头详细信息楼层模板

cwdobuhd  于 2023-02-13  发布在  Flutter
关注(0)|答案(1)|浏览(110)

我尝试使用连接选择来选择两个表头和明细。查询返回什么对象/列表值?我在flutter中使用了Floor ORM,但生成时不成功
这是我的班型和刀

flutter pub run build_runner build                                                    
[INFO] Running build...
[INFO] 1.0s elapsed, 0/2 actions completed.
[INFO] 2.1s elapsed, 0/2 actions completed.
[INFO] 8.4s elapsed, 0/2 actions completed.
[SEVERE] floor_generator:floor_generator on lib/database/Database.dart:

ERORR 
Can not define return type
package:myapp_sfaf/database/dao/SalesOrderDao.dart:35:16
   ╷
35 │   Future<List> getListHeaderDetailByIdHso(String idHso);
   │                ^^^^^^^^^^^^^^^^^^^^^^^^^^
   ╵
[INFO] Running build completed, took 8.8s

[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 59ms

[SEVERE] Failed after 8.8s
pub finished with exit code 1

class SalesOrderHd.dart
import 'package:floor/floor.dart';
import 'package:myapp_sfaf/database/entity/Customer.dart';
import 'package:myapp_sfaf/database/entity/Salesman.dart';
@Entity(tableName: 'thd_so',
          indices: [Index(value: ['docCode'],unique: true)],
          foreignKeys: [
                ForeignKey(
                   childColumns: ['idCust'],
                  parentColumns: ['custId'],
                         entity: Customer,
                       onDelete: ForeignKeyAction.restrict 
                 ),
                ForeignKey(
                   childColumns: ['idSals'],    
                  parentColumns: ['idSalesman'],
                         entity: Salesman,
                       onDelete: ForeignKeyAction.restrict
                )
          ]

)
class SalesOrderHd {
  @primaryKey
  final String idHso;
  final String custCode;
  final String custName;
  final String address;
  final String docCode;

  SalesOrderHd(
      this.idHso,  this.custCode,  this.custName,  this.address, this.docCode
      );

}

class SalesOrderDt.dart
import 'package:floor/floor.dart';
import 'package:myapp_sfaf/database/entity/ProductItem.dart';
import 'package:myapp_sfaf/database/entity/SalesOrderHd.dart';
@Entity(tableName: 'tdd_so')
class SalesOrderDt {
  @primaryKey
  final String id;
  final String docCode;
  final String itemCode;
  final String itemName;

   SalesOrderDt(
      this.id,this.docCode,  this.itemCode, this.itemName
            );
 
}

SalesOrderDao.dart
@dao
abstract class SalesOrderDao {

  @Query('SELECT hd.custName,hd.address, dt.itemCode, dt.itemName FROM thd_so hd 
          left join tdd_so dt WHERE hd.docCode = dt.docCode AND hd.idHso = :idHso')
  Future<List> getListHeaderDetailByIdHso(String idHso);

}

不管是查询错误还是因为返回值不是我写的,我希望查询的返回值是一个列表对象模型,谢谢你的帮助,

i7uq4tfw

i7uq4tfw1#

问题解决了,我使用@DatabaseView。我创建了一个class .dart文件

@DatabaseView('SELECT thd_so.custName, thd_so.address, tdd_so.itemCode,
            tdd_so.itemName FROM thd_so, tdd_so
            WHERE thd_so.docCode == tdd_so.docCode ',
            viewName: 'myJoinedObject')
class MyJoinedObject{
  String custName;
  String address;
  String itemCode;
  String itemName;
  MyJoinedObject(this.custName, this.address, this.itemCode, 
                 this.itemName);
}

在Dao文件中

@Query('SELECT * FROM MyJoinedObject')
Stream<List<MyJoinedObject?>> getStreamedStuff();

用过的

getStreamedStuff(){
Stream<List<MyJoinedObject?>> list = 
  _salesOrderRepository.getStreamedStuff();
list.forEach((element) {
    print('${element.elementAt(0)!.itemCode}');
    print('CustName nya ${element.elementAt(0)!.custName}');
    );
 }
 );
}

相关问题