NoBrainerORM / nobrainer

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

`Pluck` is not consistent with Rails API #152

Closed kuldeepaggarwal closed 9 years ago

nviennot commented 9 years ago

Can you provide a more detailed explanation?

kuldeepaggarwal commented 9 years ago

In this line, I need to manually loop over the column and get the array of values and also need to apply without_ordering and raw clause.

nviennot commented 9 years ago

I see. the API is consistent with http://rethinkdb.com/api/ruby/pluck/ and http://rethinkdb.com/api/ruby/without/

So the API is consistent with the RethinkDB API, and not with ActiveRecord. I'm not sure going away from the RethinkDB API is a good choice. I'd rather provide an option to pluck() to provide the behavior you need. Any suggestions?

kuldeepaggarwal commented 9 years ago

But then I should not need to use without_ordering clause.

nviennot commented 9 years ago

Adding without_ordering is not necessary. The default ordering is only there to provide a deterministic response.

nviennot commented 9 years ago

So you have two ways to achieve what you want:

  1. With objects. Here, name is called on each returned object, giving you the ability to go through user defined getters.
def names
  pluck(:id, :name).map(&:name)
end
  1. With RQL. All the work is done by the DB:
def names
  NoBrainer.run { rql_table.map { |doc| doc['name'] } }
end
kuldeepaggarwal commented 9 years ago

Why ordering is there in every query?

nviennot commented 9 years ago

So results are deterministic. Further details at http://nobrainer.io/docs/fields/#primary_key