ruby on rails - Can't access polymorphic association from test, but can from browser -


note 2 puts lines in method. when accessed followers, result empty, whereas when accessed follower.all, result contains 1 or more expected objects.

how can be?

book.rb (model)

has_many :followers, as: :followable, dependent: :destroy  def followed_by_user?(user)     puts "--- followers: #{followers.inspect}"       # empty     puts "--- follower.all: #{follower.all.inspect}" # contains expected user     followers.map{|l| l.user_id}.include?(user.id)   # returns false end 

there's no logical contradiction. first puts shows followers associated this instance of user; second puts showing all of followers, including ones associated other users.

so it's reasonable first set empty , second set non-empty.


Comments

Popular posts from this blog

c++ - OpenMP unpredictable overhead -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

javascript - Wordpress slider, not displayed 100% width -