Closed Smef closed 4 months ago
Queries return different object types when using get() vs other retrieval methods, such as chunk, chunkById, lazy, or others.
The core query builder that this package inherits from (https://github.com/statamic/cms/blob/4.x/src/Query/EloquentQueryBuilder.php) has only implemented the methods used by the core package, or that other developers have required and added PRs for.
It would be great to have these different query types return the same object type.
It should be a case of adding those methods to the core query builder, similar to get(): https://github.com/statamic/cms/blob/7156abf4979414387c79ebbf318f87ca5171db9a/src/Query/EloquentQueryBuilder.php#L53-L66
Alternatively, being able to query the database using a regular model query and get models back including all the entry functionality of an Entry would be fantastic, which I think would mean expanding the functionality of the EntryModel to be more similar to the Entry object
This approach wont happen as it goes against the repository pattern.
Also for what its worth, you can query using the EntryModel using any eloquent builder methods, then simply call \Statamic\Eloquent\Entries\Entry::fromModel
on any of the resulting models to turn it into an Entry class. Maybe an alternative way of approaching it which gives you the best of both worlds.
This all sounds good. Thanks! fromModel
will definitely be something we use in the future.
chunk() and lazy() are now supported in core, so I'm going close this off.
Queries return different object types when using
get()
vs other retrieval methods, such aschunk
,chunkById
,lazy
, or others.Using
limit(xx)->get()
returns aStatamic\Eloquent\Entries\Entry
object Usingchunk()
provides aStatamic\Eloquent\Entries\EntryModel
object to the callback functionThese two objects behave differently, and getting different objects back is an unexpected result. In particular,
EntryModel
objects don't seem to go through the entry populating process thatEntry
objects do. This results in things like computed properties not loading.It would be great to have these different query types return the same object type. Alternatively, being able to query the database using a regular model query and get models back including all the entry functionality of an
Entry
would be fantastic, which I think would mean expanding the functionality of the EntryModel to be more similar to the Entry object.