I have a table structure where a customer can have many addresses, that may be active or not. A typical one-to-many scenario.
Table Customer
id | name |
---|---|
1 | customer a |
2 | customer b |
Table Address
id | is_active | fk_customer |
---|---|---|
1 | false | 1 |
2 | true | 1 |
3 | true | 2 |
I wanna have an object Customer for exact one specific customer with all its active addresses (as an Object collection on the customers “address” property). Therefore, I am doing something like this for customer a
.
CustomerQuery::create()
->joinWithAddress()
->useAddressQuery()
->filterByIsActive(true)
->endUse()
->findOneByIdCustomer(1);
But I get the error
Cannot use limit() in conjunction with with() on a one-to-many relationship. Please remove the with() call, or the limit() call.
Where the find()->getFirst()
call on the other hand is working perfectly and returns an object collection with exactly one result.
I think this is due the fact that “findOne” is actually just adding a limit 1
to the query which may potentially return multiple rows … but shouldn’t this be mapped by propel correctly anyway because the findOneByIdCustomer()
makes the resulting row definitely unique?
How to “rewrite” the query so that not multiple results are assumed an findOne
can be used?