Ich habe eine Sammlung von characters
in following
. Jeder character
hat einen einzigartigen Griff. Ich habe die Datenbank überprüft, um sicherzustellen, dass es nur eine character
mit dem Handle barry1
gibt. Ich versuche zu tun:Schienen nicht verstehen .include? Verhalten
following.include?(other_character) # false
Es ist falsch Rückkehr, aber ich bin sicher, dass barry1
in following
ist. Es denkt, dass die id
s sind anders, aber es gibt nur eine barry1
. Was ist los?
character.rb
has_many :following, through: :active_follow_relationships, source: :followed
Puts:
puts following.first.handle # barry1
puts other_character.handle # barry1
puts following.first # #<Character:0x007fef15231490>
puts other_character # #<Character:0x007fef09bb4d58>
puts following.first.id # 21
puts other_character.id # 8
Sie es in Ihrer Lösung haben folgende [21] nicht other_character [8] – MZaragoza
Include funktioniert nicht, wenn Objekte nicht identisch sind. Wenn Sie die Aufnahme durch die Handle-Eigenschaft überprüfen möchten, tun Sie Folgendes: following.any? {| f | f.handle == other_character.handle} –