crud icon indicating copy to clipboard operation
crud copied to clipboard

IndexAction ignores `belongsToMany` association conditions

Open geoidesic opened this issue 5 years ago • 0 comments

I’m using friendsofcake/crud I have a pivot table EnquiryContacts which joins Enquiries, Roles and People tables. The EnquiriesTable has a belongsToMany association:

$this->belongsToMany('Clients', ['through' => 'EnquiryContacts', 'className' => 'People', 'conditions' => ['role_id' => 3], 'foreignKey' => 'enquiry_id', 'targetForeignKey' => 'person_id']);

And the PeopleTable has the reverse association:

$this->belongsToMany('ClientEnquiries', ['through' => 'EnquiryContacts', 'className' => 'Enquiries', 'conditions' => ['role_id' => 3], 'foreignKey' => 'person_id', 'targetForeignKey' => 'enquiry_id']);

But results returned by IndexAction will include records with any role_id, instead of just those within the conditions.

Is this expected behaviour or a bug? If expected, how should I go about ensuring a response that takes the conditions of the association into account?

geoidesic avatar Sep 12 '20 08:09 geoidesic