NoBrainerORM / nobrainer

Ruby ORM for RethinkDB
http://nobrainer.io/
Other
386 stars 49 forks source link

:attr.include => "something" does not work while querying #220

Closed 34code closed 8 years ago

34code commented 8 years ago

I get the following error when trying to use .include in the query..

original query:

@orders = @user.orders.where(or:[{buy_status: "purchased"}, 
{buy_status: "ordered"}]).where(:order_id.include => "foo").order_by(:created_at => :desc)

heres the query nobrainer generates.

Cannot convert STRING to SEQUENCE Backtrace: r.table("orders").get_all( "usersuuid", {"index" => :user_id} ).filter {|var_189| r(["purchased", "ordered"]).contains(var_189[:buy_status]).and( var_189[:order_id].map {|var_190| var_190.eq("foo")}.contains(true) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) }.order_by(r.desc(:created_at)).skip(0).limit(7)

nviennot commented 8 years ago

Can you provide me a way to replicate that bug?

34code commented 8 years ago

hmm -- I'm not sure its specific to my codebase.. would nobrainer and rethinkdb versions help?

nviennot commented 8 years ago

Just provide me with a standalone ruby script that replicate that issue. Something along these lines:

require 'bundler'
Bundler.require

NoBrainer.configure do |c|
  c.app_name = "issue220"
  c.environment = "test"
  c.logger = Logger.new(STDERR).tap { |l| l.level = Logger::DEBUG }
end

class User
  include NoBrainer::Document
  has_many :orders
end

class Order
  include NoBrainer::Document
  belongs_to :user
end

user = User.create!
user.orders... # run the thing
nviennot commented 8 years ago

wait, I'm looking at the query again. it makes no sense. :order_id.include => "foo" means that order_id is an array containing a bunch of strings, and you want one of the string to be "foo". I think you meant :order_id => "foo" in your query. If you want to use match, you just use a regexp: where(:order_id => /foo/).