In SilverStripe 3 I have two related DataObjects, Order
and OrderItem
. Order
has many OrderItems
. OrderItem
has one Order
.
I am managing Order
with ModelAdmin.
I can create a new OrderItem
but when it tries to load I get the following error:
SELECT DISTINCT "OrderItem"."ClassName", "OrderItem"."Created", "OrderItem"."LastEdited", "OrderItem"."ItemQuantity", "OrderItem"."ItemDiscount", "OrderItem"."OrderID", "OrderItem"."ProductID", "OrderItem"."ID", CASE WHEN "OrderItem"."ClassName" IS NOT NULL THEN "OrderItem"."ClassName" ELSE 'OrderItem' END AS "RecordClassName", "Product"."Title" FROM "OrderItem" WHERE ("OrderID" = '9') AND ("OrderItem"."ID" = 11) ORDER BY Product.Title ASC LIMIT 1
Unknown column 'Product.Title' in 'field list'
Here is my code:
class Order extends DataObject {
public static $db = array(
'OrderDate'=>'Date',
'FulfilledDate'=>'Date',
'OrderStatus'=>'Enum("New, InvoiceRequested, InvoiceSent, Paid, Cancelled")',
'ShippingStatus'=>'Enum("Unshipped, Shipped")'
);
public static $has_one = array(
'Customer' => 'Customer'
);
public static $has_many = array(
'OrderItems' => 'OrderItem'
);
// ...
}
class OrderItem extends DataObject {
public static $db = array(
'ItemQuantity'=>'Int',
'ItemDiscount'=>'Decimal'
);
public static $summary_fields = array(
'Product.Title',
'ItemQuantity',
'ItemDiscount'
);
public static $has_one = array(
'Order' => 'Order',
'Product' => 'Product'
);
// ...
}
Any thoughts on how can I add a join in ModelAdmin to the Product
object/table?
Edit
I have found the problem I had.
public static $default_sort = array('Product.Title');
Removing that fixed the issue.