Objectiphy
  • Introduction
  • Quick Start
  • Basic Fetching
  • Basic Saving
  • Deleting
  • Mapping Providers
    • Attributes
    • Objectiphy Mapping
    • Doctrine Mapping
  • Defining Relationships
    • One to one
    • One to Many
    • Many to one
    • Many to Many
    • Scalar Joins
  • Query Builder
    • Running a Query
    • Select Queries
    • Update Queries
    • Insert Queries
    • Delete Queries
    • Criteria
      • Operators
      • Filtering by Child Objects
      • Filtering by Aggregates
    • Joins
  • Pagination and Sorting
  • Embedded Value Objects
  • Serialization Groups
  • Late Binding and Lazy Loading
  • Streaming Results
  • Custom Repositories
  • Optimisation
  • Configuration Options
  • Mapping Overrides
  • Caching
  • Comparison with Doctrine
  • Code Generation etc.
  • Troubleshooting
  • Licence, Copyright, Credits
Powered by GitBook
On this page

Was this helpful?

Streaming Results

You can load records one at a time to enable exporting large amounts of data to a file.

If you need to export a large amount of data, and want to fetch and hydrate one record at a time (so as not to run out of memory), you can ask for an iterable result by calling findOnDemandBy. Instead of getting back an array of entities, you will get an instance of the IterableResult class - which implements PHP's \Iterator interface. Each iteration of the result will fetch and hydrate a new record from the database (keeping the database connection open throughout) - just like using fetch with PDO. As the query is kept open during iteration, it is not possible to lazy load or late bind child objects with an iterable result, so lazy loading becomes disabled, and one-to-many and many-to-many relationships cannot be hydrated.

If you are exporting records to a flat file (such as a CSV), it is unlikely that you will need an object model to work with, so there is no point mapping data from the database into objects and then converting them back into an array for export, so it is usually best to call $repository->setConfigOption(ConfigOptions::BIND_TO_ENTITIES, false) before requesting an iterable result (the results that you iterate through will then be associative arrays).

PreviousLate Binding and Lazy LoadingNextCustom Repositories

Last updated 3 years ago

Was this helpful?