join<Tb> method

TupleJoinQuerySource<TDao, Tb> join<Tb>(
  1. DataBean<Tb> other, {
  2. Filter? filter,
})

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,
    {Filter? filter}) {
  if (filter == null) {
    final foreignField = fields
        .whereType<ForeignKey>()
        .firstOrNullWhere((f) => other.fields.contains(f.foreignPrimaryKey));
    final mainField = foreignField;
    final otherField = foreignField?.foreignPrimaryKey;
    filter = mainField?.equals(otherField);
  }

  if (filter == null) {
    throw PersistenceException(
        'Could not autodetect join relation between "$runtimeType" and "${other.runtimeType}".');
  }

  return TupleJoinQuerySource(this, BeanJoin(other, filter));
}