我有一个包含 4 个连接的查询。所有 4 个连接都基于mWeeklyAimEntries
. 我想将查询限制为mWeeklyAimEntries
. 当我限制选择时,它会限制整个查询。需要明确的是,我希望 sql 在第四个之后停止mWeeklyAimEntries
并且它是连接的。
Future<Map<int, MainAimObject>> getAims(List<int> days,
{List<int>? lessonIds,
List<int>? excludedLessonIds,
List<AimType>? aimTypes,
int? limit}) async {
var lesson = alias(mLessons, "l");
var topic = alias(mTopics, "t");
var questions = alias(mQuestions, "q");
var studies = alias(mSessionEntries, "s");
Expression<bool> dayExp = getDayExpression(days);
var weeklyAims = (select(mWeeklyAimEntries).join([
leftOuterJoin(
lesson, lesson.id.equalsExp(mWeeklyAimEntries.lessonId) & dayExp),
leftOuterJoin(
topic, topic.id.equalsExp(mWeeklyAimEntries.topicId) & dayExp),
if (aimTypes == null || aimTypes.contains(AimType.questionSolving))
leftOuterJoin(
questions,
questions.lessonId.equalsExp(mWeeklyAimEntries.lessonId) &
getDayTimestampExpression(days, "q")! &
questions.topicId.equalsExp(mWeeklyAimEntries.topicId)),
if (aimTypes == null || aimTypes.contains(AimType.workTime))
leftOuterJoin(
studies,
studies.lessonId.equalsExp(mWeeklyAimEntries.lessonId) &
getDayTimestampExpression(days, "s")! &
studies.topicId.equalsExp(mWeeklyAimEntries.topicId)),
]));
if (limit != null) weeklyAims.limit(limit);
weeklyAims.where(dayExp);
if (lessonIds != null) weeklyAims.where(getLessonExpression(lessonIds));
if (excludedLessonIds != null)
weeklyAims.where(getLessonExpression(excludedLessonIds, not: true));
//AFTER THAT, I GET THE QUERY
.
.
.
}