A client has many different colored shirts: red, blue, pink etc. I want to pick out all clients with red shirts. How?
Shirts are stored like this:
c = Client.last
c.shirt #=> "red,blue,pink"
If the client had one colored shirt, I'd get the information like:
Client.where(shirt: "red")
But since a client will have many shirts, I need something like include?
. The English would be: Give me all clients that has a red shirt. How do you write that?
c = Client.all
c.map do |m| m.shirt.include? "red" end #=> [0] true
I like to return an array of clients with red shirts.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…