rails scope without associations -


i have model called "activos", need show records not associated model called "relactivo".

i've been trying in model: scope :ts, -> { includes(:relactivo).where(relactivo: { activo: nil}) }

this model "activos"

class activo < activerecord::base   self.primary_key = "idactivos"    scope :ts, -> { includes(:relactivo).where(relactivo: { activo: nil}) }     has_one :relactivo, class_name: "relactivo", foreign_key: "activo"   end 

and model "relactivo"

class relactivo < activerecord::base   self.primary_key = "idrow"   belongs_to :activo, class_name:"activo", foreign_key: "activo"  end 

try doing scope:

class activo < activerecord::base   self.primary_key = "idactivos"      scope :ts, -> { joins('left outer join relactivos on relactivos.idactivos = activos.idactivos relactivos.idactivos null'))) }      has_one :relactivo, class_name: "relactivo", foreign_key: "idactivos"    end 

see if works, custom primary/foreign key makes little strange try this.


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -