Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Moor join and where

My Dependencies for moor:

  moor_flutter: ^2.1.1
  moor_ffi: ^0.4.0

I have the tables:

  • netPoint = Information about the netPoint
  • netPointNetPoint = linking of netpoints

I want all netPoints that match the "PARENTS_ID" s. below.

My problem is that I cannot access netPointNetPoint in the Where condition.

select(netPoint)
    ..where((t) => t.TYPE.equals(type))
    ..join(
        [
          innerJoin(netPointNetPoint, netPointNetPoint.CHILDREN_ID.equalsExp(netPoint.ID)),
          innerJoin(netPointNetPoint, netPointNetPoint.PARENTS_ID.equals(parentId))
        ]
    )
  ).get();

Unfortunately the help page https://moor.simonbinder.eu/docs/advanced-features/joins/ did not help me.

like image 699
osion Avatar asked Jan 20 '26 15:01

osion


1 Answers

Well, the questions is quite old, but I've faced the same problem and just in case some one will have the same problem. I guess you had to change the expressions with something like this:

select(netPoint)
..where((t) => t.TYPE.equals(type))
..where((t) => netPointNetPoint.PARENTS_ID.equals(parentId))
..join(
    [
      innerJoin(netPointNetPoint, netPointNetPoint.CHILDREN_ID.equalsExp(netPoint.ID))
    ]
)).get();

The join's result will have all the columns you need, hence you just need to check that the column in the row has needed value. E.g. netPointNetPoint.PARENTS_ID.equals(parentId).

like image 72
Sergey Yamshchikov Avatar answered Jan 22 '26 20:01

Sergey Yamshchikov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!