jjzjj

ruby - 我可以使用 AREL/ActiveRecord 更优雅地编写此查询吗?

我能否使用AREL/ActiveRecordAPI将此查询写得更短和/或更优雅?Foo.where("(barisnotnullandbar!='')or(bazisnotnullandbaz!='')") 最佳答案 您可以直接对Arel执行OR运算符,但语法不是很漂亮并且可能有点难以阅读。这是它在arel中的样子:foo=Foo.arel_tableFoo.where(foo[:bar].not_eq(nil).and(foo[:bar].not_eq('')).or(foo[:baz].not_eq(nil).and(foo[:

ruby - Rails3 Arel 访问自定义类

我有一个自定义类,但我希望能够将它传递给Arel并让它解析它的可查询部分。moduleCustomclassItemattr_accessor:namedefinitialize(name)self.name=nameendendendcustom_item=Custom::Item.new("Bill")User.where(:name=>custom_item)有什么我可以在custom_item中定义的,所以它会理解Arel想要它的名字吗?目前我的解决方法是:moduleArelmoduleVisitorsclassToSqldefvisit_Custom_Itemo"'#{o.