added debug and fix for has_many :through a join table