Tag: 其中

找到多态关联或无差异的记录

我有一个运行ruby 2.1.2和rails 4.1.1的rails应用程序,在其中我有一个多态关联,如下所示: class Picture < ActiveRecord::Base belongs_to :imageable, polymorphic: true end class Employee < ActiveRecord::Base has_many :pictures, as: :imageable end class Product < ActiveRecord::Base has_many :pictures, as: :imageable end 我希望能够找到属于给定员工或没有关联的“可成像”记录的所有图片。 # These both work fine Picture.where(imageable: Employee.first) # finds all associated with Employee.first Picture.where(imageable: nil) # finds all un-associated Pictures #This does not work […]