join<Tb> method
TupleJoinQuerySource<TDao, Tb>
join<Tb>(
- DataBean<
Tb> other, { - DataField? mainField,
- DataField? otherField,
- CompareType type = CompareType.equals,
Create JoinedQuerySource where this DataBean is used as main source.
This will create an inner join. (Both return types will be non-null)
When mainField
and otherField
are null, the only ForeignKey of
this is used as mainField
and the corresponding PrimaryKey of other
is used as otherField
. If this bean has multiple ForeignKeys to
other
, this throws a PersistenceException.
Implementation
TupleJoinQuerySource<TDao, Tb> join<Tb>(DataBean<Tb> other,
{DataField? mainField,
DataField? otherField,
CompareType type = CompareType.equals}) {
if ((mainField == null) != (otherField == null)) {
throw PersistenceException(
'mainField and otherField must be either both null or both non-null.');
}
if (mainField == null && otherField == null) {
final foreignField = fields
.whereType<ForeignKey>()
.firstOrNullWhere((f) => other.fields.contains(f.foreignPrimaryKey));
mainField = foreignField;
otherField = foreignField?.foreignPrimaryKey;
}
if (mainField == null || otherField == null) {
throw PersistenceException(
'Could not autodetect join relation between "$runtimeType" and "${other.runtimeType}".');
}
return TupleJoinQuerySource(
this, BeanJoin(other, mainField, type, otherField));
}