Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Join order on Datalist Count

Go to End



Community Member, 3 Posts

23 August 2012 at 8:19pm

Encountered an issue with using the ORM in Silverstripe 3.

I have a DataObject OrderItem, and Deal inherits from OrderItem. Deal has a has_one Mechanic (Member).

The issue arises when I try to use the filter function

$deals = Deal::get()->filter(array(
        "Mechanic.SuburbID:ExactMatch" => $suburb

It gives an error on DataList->Count. The issue appears to be that it joins on the Mechanic (Member table) before it joins on the Deal table.

I am able to get around the issue by explicitly joining the Deal table with ->leftJoin before calling filter.

Also, I've found the relations only seem to work when you use a search filter with them, e.g. "Mechanic.SuburbID:ExactMatch" => $suburb works but "Mechanic.SuburbID" => $suburb doesn't.