I'm getting a strange error. I have Customers and Messages.... Customers has_many Messages.. and message belongs_to customer The customer has a phone column and a message has a to column. The code below is suppose to take the current customer id and grab the phone column then find all messages that match the phone based on the to column. Then update all the messages with the customer id.
I'm getting this error that I don't see the problem. Can someone tell me what I'm doing wrong? The error is triggered on the each loop. I tried to inspect @foundmessage_all but that doesn't work.
PG::SyntaxError: ERROR: syntax error at or near "to" LINE 1: SELECT
"messages".* FROM "messages" WHERE (to = '2081234567'... ^ : SELECT
"messages".* FROM "messages" WHERE (to = '2081234567' )
customer/show.rb
@customer = Customer.find(params[:id])
tempphone = @customer.phone
@foundmessage_all = Message.where('to = ? ', tempphone)
if @foundmessage_all != nil
@foundmessage_all.each do |t|
t.update_attribute(:customer_id, @customer.id)
end
else
#other stuff
end