difference between ..join vs .join and ..where vs .where ? #1274
-
i'm wondering, what's the difference between ..join vs .join and ..where vs .where ? this q came as a result of the problem i'm trying to figure out below if i can get some help with this too please. using a ..where after a .join, i found i get this error: if i switch to using ..where after ..join, then it works fine. in my map after awaiting a get on the query, i found the rows param is the type for the table that my select has specified. and, my rows param doesn't know about the joined table, even though the join has useColumns: true for the 2nd param. i'm wondering is what i'm experiencing with the rows param related to using ..join and ..where instead of .join and .where. i found that i use .join and remove my ..where, then the type of my rows param in map is TypedResult, which is what i need. changing that .join back to ..join, it is as described above and no longer TypedResult. so, if i use .join and try to use .where, i'm having this problem with my where: the where i'm trying to use in a .where (with the .join so i can have a TypedResult), is like this: #767 (comment) the reason i want a TypedResult, is so that i can map the query result from these 2 joined tables into a custom class, such as here: https://moor.simonbinder.eu/docs/advanced-features/joins/?#joins |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
The Through a bit of an unfortunate design choice, you should use final query = select(myTable).join([...]);
query..where(myPredicate)..limit(1);
return query.watchSingle(); |
Beta Was this translation helpful? Give feedback.
The
..
operator in Dart is called the cascade notation. Basically, it allows invoking a method while evaluating to the value the method was called on. For instancemyList..clear()
evaluates tomyList
while also calling itsvoid clear()
method.Through a bit of an unfortunate design choice, you should use
..
for every method on a select statement except forjoin()
. Methods likewhere
,orderBy
andlimit
all returnvoid
, so the cascading notation is a perfect tool to add those clauses to a query without using a temporary variable.By design,
join
does not returnvoid
but aJoinedSelectStatement
. If you used..join()
, you'd still get the original select statement without the join as that's ho…