I have two model A and B. A has_many B’s. B has an attribute :number
What is the rails way (I could do some coding with each, but that’s not the point) to find if an A has a B object with a given number ?
I’ve tried find but since it’s an association, it gives me this error:
>> bs.find{|f| f.number == 8}
>> ActiveRecord::RecordNotFound: Couldn't find A without an ID
EDIT
To make more clear.
If I had to code this would be something like:
def is_number_in_use(number)?
self.bs.each do |b| #Consider bs as the has_many association between A and B
return true if b.numero == number
end
return false
end
Is that better?