Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't quote array - rails sql

Im trying to create a sql query dynamically with the following syntax:

Company.joins(:founder_persons)
       .where("people.first_name like people[:first_name]", {people: {first_name: 'm%'}})

But running this on the rails console gives me TypeError: can't quote Array. Im guessing this is not how we use the where string? What's the right way to fix this error? Thanks.

like image 716
Mohammad Areeb Siddiqui Avatar asked Oct 25 '25 08:10

Mohammad Areeb Siddiqui


1 Answers

One reason this error can occur is with a nested array used as SQL value.

Example:

Article.where(author: ['Jane', 'Bob'])

works, but:

Article.where(author: ['Jane', ['Bob']])

would give the error. A quick fix would be to run flatten on the array.

(Mentioning this since this page comes up when searching for the confusing error "Can't quote array".)

like image 85
mahemoff Avatar answered Oct 27 '25 00:10

mahemoff