Reputation: 41
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?
I have found the problem I had.
public static $default_sort = array('Product.Title');
Removing that fixed the issue.
Upvotes: 4
Views: 749
Reputation: 4278
Just so there is one less unanswered question, @MilesParker edited into the question:
I have found the problem I had.
public static $default_sort = array('Product.Title');
Removing that fixed the issue.
This line would have been on the OrderItem
class as that is what the SQL error shows. The issue could have been caused by the lack of a dev/build
however it may have also been due to a bug in that specific version of Silverstripe 3.0.
Upvotes: 2