Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我创建了一个如下范围:
scope :except_me, -> { where( "id != ?", self.id ) }
但是此代码会产生错误:没有类 blah 的属性 ID。self 在范围内指向什么以及如何更正此代码?
范围内的 Self 指向类本身,而不是实例。您需要将实例传递给范围以将其从查询中排除:
scope :except, -> item { where( "id != ?", item.id ) }