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?

  1. Query Builder
  2. Criteria

Filtering by Child Objects

PreviousOperatorsNextFiltering by Aggregates

Last updated 3 years ago

Was this helpful?

The property that you search on does not have to be a property of the parent entity - you can use child objects - even with relationships. To specify a child, use the property name of the property that contains the child (or children), followed by a dot, followed by the property on the child object that you want to filter by. You can even go further than an immediate child, and filter by 'grandchild' properties, by just continuing with the dot notation.

For example, if you have a parent entity which has a property with a relationship called child, and the child entity has a property with a relationship called pets, you can search for all parents which have a child who has a dog, like this:

$query = QueryBuilder::create()
    ->where('child.pets.type', QB::EQUALS, 'dog')
    ->buildSelectQuery();

If you want to embed a property path in some SQL (eg. to use a MySQL function like CONCAT), you can do so by wrapping the property path in percent delimiters, eg:

$query = QueryBuilder::create()
    ->where("CONCAT(%child.pets.type%, %child.pets.name%)", '=' 'DogRover')
    ->buildSelectQuery();
one-to-many
one-to-one
one-to-many