Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Hi here is my ActiveRelation query that works fine on local development environment (SQLite)

@table2_items = @table1var.table2_items.find(:all, conditions: ["status1 is ? AND status2 is ? AND start_datetime > ?", true, nil, Time.now.to_datetime], order: [:field_id, :created_at])

I think it's just a syntax error... Can anyone help? Thanks

share|improve this question

1 Answer

up vote 2 down vote accepted

Your SQL ends up with this in it:

status1 is 't'

and that's invalid: is is only used with is null, is distinct from, and similar constructs.

You should upgrade to a more modern syntax and leave most of the work to ActiveRecord:

@table2_items = @table1var.table2_items
                          .where(:status1 => true, :status2 => nil)
                          .where('start_datetime > ?', Time.now)
                          .order(:field_id, :created_at)

That leaves most of the "how do I compare things?" logic up ActiveRecord and is a bit easier to read as the placeholders and their values aren't separated from each other.

Once you have this problem sorted out, you really should install PostgreSQL in your development environment so that you're developing and deploying on the same stack. There are all sorts of differences between databases that no ORM can protect you from.

share|improve this answer
fantastic, this worked, many thanks! This syntax looks very straightforward so I will use it from now on, and yes will upgrade local to Postgres.. – switcher yesterday

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.