Учитывая, что я следующую структуру:Rails3 has_and_belongs_to_many - ошибка при получении атрибута из таблицы объединения
class A < ActiveRecord::Base
has_and_belongs_to_many :bs, :class_name => "B", :join_table => "ab"
end
class AB < ActiveRecord::Base
#ab has a date column "creation_date"
#ab also has a text column "creatior"
end
class B < ActiveRecord::Base
end
Я успешно извлекать "CREATION_DATE" атрибут в rails console
console> A.find(1).bs.first.creation_date
=> "14/08/1874"
В контроллере
@a = A.find(1)
@bs = a.bs
Но используя его в виде (частичном), я получил следующую ошибку
bs.each do |b|
b.b_attribute #this is O.K.
b.creation_date # cause error => undefined method `creation_date` for #<B:...>
end
# also try to debug in partial
A.find(1).bs.first.creation_date #=> this return data correctly
Проблема, как показано выше, что может привести к возможно undefined method
в то время как непосредственные атрибуты по-прежнему доступны.
У кого-нибудь есть идеи, что не так с моим кодом?