Ruby on rails Rails-从查找表访问时间戳

Ruby on rails Rails-从查找表访问时间戳,ruby-on-rails,timestamp,Ruby On Rails,Timestamp,我试图从查找表中创建的时间戳中获取值。假设我有配料和食谱,还有一张叫做配料食谱的表格,上面有配料id,食谱id,还有时间戳 我怎样才能访问这些时间戳?基本上,我需要知道一种特定的配料是什么时候添加到食谱中的 谢谢 那么你现在有这样的东西 class ingredient << ActiveRecord::Base has_and_belongs_to_many :recipes ..... end class recipe << ActiveRecord::Ba

我试图从查找表中创建的时间戳中获取值。假设我有配料和食谱,还有一张叫做配料食谱的表格,上面有配料id,食谱id,还有时间戳

我怎样才能访问这些时间戳?基本上,我需要知道一种特定的配料是什么时候添加到食谱中的


谢谢

那么你现在有这样的东西

class ingredient << ActiveRecord::Base
  has_and_belongs_to_many :recipes
  .....
end

class recipe << ActiveRecord::Base
  has_and_belongs_to_many :ingredients
  ....
end

通过这种方式,您可以将属性添加到混合表中,这样您就可以知道它们是何时添加到何处的,是谁添加的等等

虽然不是便携式解决方案,但您可以使用
find\u by\u sql
attr\u访问器
提取该信息,谢谢您的回复。你能提供更多信息的链接吗?非常感谢。
class ingredient << ActiveRecord::Base
  has_many :mixtures
  has_many :recipes , :through=> :mixtures
  .....
end

class recipe << ActiveRecord::Base
   has_many :mixtures
   has_many :ingredients, :through=> :mixtures
  ....
end

class mixture << ActiveRecord::Base
  belongs_to :recipe
  belongs_to :ingredient
  ...
end