我有一个嵌套到Message模型的Phone模型.考虑到数字属性在Phone模型内而不在Message中,我怎样才能找到给定数字的所有消息?
这就是我现在所拥有的
- class Message < ActiveRecord::Base
- attr_accessible :phone_id
- belong_to :phone
- end
- class Phone < ActiveRecord::Base
- attr_accessible :phone
- has_many :messages
- end
解决方法
- Message.joins(:phone).where("phones.phone = ?","123-456-7890").all