Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

relatedModels doesn't work correctly with join conditions #535

Closed
lilHermit opened this issue Jun 2, 2017 · 1 comment
Closed

relatedModels doesn't work correctly with join conditions #535

lilHermit opened this issue Jun 2, 2017 · 1 comment

Comments

@lilHermit
Copy link

As RelatedModel listener effectively uses "select" strategy it breaks join conditions.

For example in AccessTokensTable

$this->belongsTo('Users', [
    'foreignKey' => 'foreign_id',
    'conditions' => ['AccessTokens.foreign_type' => 1]
]);

$this->belongsTo('Devices', [
    'foreignKey' => 'foreign_id',
    'conditions' => ['AccessTokens.foreign_type' => 2],
]);

This works fine with standard scaffold templates "paginate" (index) and "get(id)" (view)

However I get
SELECT Users.id AS Users__id, Users.name AS Users__name FROM users Users WHERE AccessTokens.foreign_type = :c0
when using crud.relatedModel listener as foreign_type is in AccessTokens

It also works on in crud generally as in view I'm adding containing models like so

$this->Crud->on('beforeFind', function (\Cake\Event\Event $event) {
    /**
     * @var \Cake\ORM\Query $query
     */
    $query = $event->getSubject()->query;
    $query->contain(['Users', 'Devices']);
});
return $this->Crud->execute();
@geoidesic
Copy link

I have a similar issue which I've reported here: FriendsOfCake/crud-json-api#135

In which the URL http://{{domain}}/api/enquiries/5/clients is handled by crud's IndexAction. The conditions of the associations are not taken into account during find.

@jippi jippi closed this as completed Dec 4, 2020
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

No branches or pull requests

3 participants