我有那些典型的 class VisibilityColumn : IValueConverter
{
public CollectionViewSource CurrentCollection { get; set; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
List<string> castedCollection = (List<string>)CurrentCollection.Source;
bool result=castedCollection.Exists(x => x == (string)parameter);
if (result == true)
return Visibility.Visible;
else
return Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new Exception("The method or operation is not implemented.");
}
}
,Order
,LineItem
。
Product
有Order
个,LineItem
有LineItem
个字段。
我正在尝试根据名为product_id
的产品表的列对LineItem
中的Order
进行排序。
所以,这在本地工作,在MySQL数据库上,但不在生产中,我使用PostgreSQL。
code
错误:
scope :sort_by_product_id, -> {
includes(:product)
.order("products.code asc")
}
我尝试使用ActionView::Template::Error (PG::SyntaxError: ERROR: syntax error at or near "products"
LINE 1: ..._id" WHERE "line_items"."order_id" = $1 ORDER BY products...
^
: SELECT "line_items".* FROM "line_items" INNER JOIN "products" ON "products"."id" = "line_items"."product_id" WHERE "line_items"."order_id" = $1 ORDER BY products.code asc):
代替joins
,但在生产中仍然存在相同的错误。
答案 0 :(得分:1)
scope :sort_by_product_id, -> {
joins(:product)
.merge(Product.order(code: :asc))
}
答案 1 :(得分:0)
试
scope :sort_by_product_id, -> do
includes(:product).order(products: { code: :asc })
end