I have a Phone
model nested to Message
model. How can I find all Messages by a given number considering that number
attribute is inside Phone
model and not in Message
?
This is what I currently got
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: '555-555-5555' })
Message.joins(:phone).where("phones.phone = ?","123-456-7890").all
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With