Skip to content

Fix/eager loading with after select and orderby#60

Merged
benkhalife merged 3 commits into
mainfrom
fix/eager-loading-with-after-select-and-orderby
Jun 30, 2026
Merged

Fix/eager loading with after select and orderby#60
benkhalife merged 3 commits into
mainfrom
fix/eager-loading-with-after-select-and-orderby

Conversation

@benkhalife

Copy link
Copy Markdown
Member

No description provided.

Model::__callStatic() forwarded unmatched static calls (select,
orderBy, limit, ...) directly to the raw Query\Builder instead of
ModelBuilder. Only the hand-written where() went through
static::query(). As a result, Model::select(...) returned a builder
with no knowledge of relations, breaking with() when chained after
it (or after any other forwarded method).
…r loading

Adds ModelBuilder::with(), returning an EagerBuilder seeded with the
current underlying query (preserving any select/where/etc already
applied). Combined with the __callStatic fix, this makes with()
order-independent in the chain, matching the behaviour expected from
Eloquent-style ORMs (e.g. Laravel):

  Page::select('id', 'slug')->with('translations')->where(...)->first();
  Page::where(...)->with('translations')->select('id', 'slug')->first();

Previously with() only worked as the very first call via
Model::with().
Adds regression coverage for Model::select(...)->with(...) throwing
"Call to unknown method: Foxdb\Query\Builder::with()", plus several
chain-order variants (where->with->select, with->select->where),
a with() constraint-closure case, and a guard confirming plain
select() without with() is unaffected.
@benkhalife benkhalife merged commit a6e625d into main Jun 30, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant