Skip to content

Instantly share code, notes, and snippets.

@pechorin
Last active December 14, 2015 21:29
Show Gist options
  • Save pechorin/5151902 to your computer and use it in GitHub Desktop.
Save pechorin/5151902 to your computer and use it in GitHub Desktop.
without squeel `where(:id => 1).where_values` returns arel nodes. But with squeel i get hash.
irb(main):013:0> User.where(:id => 1).class
=> ActiveRecord::Relation
irb(main):012:0> User.where(:id => 1).where_values
=> [{:id=>1}]
but all is okay then i use scopes:
irb(main):007:0> class User
irb(main):008:1> scope :with_id_one, where(:id => 1)
irb(main):009:1> end
irb(main):014:0> User.with_id_one.class
=> ActiveRecord::Relation
irb(main):015:0> User.with_id_one.where_values
=> [#<Arel::Nodes::Equality:0x007f992efca2c8 @left=#<struct Arel::Attributes::Attribute relation=#<Arel::Table:0x007f992efca4d0 @name="users", @engine=User(id: integer, email: string, encrypted_password: string, reset_password_token: string, reset_password_sent_at: datetime, remember_created_at: datetime, sign_in_count: integer, current_sign_in_at: datetime, last_sign_in_at: datetime, current_sign_in_ip: string, last_sign_in_ip: string, password_salt: string, confirmation_token: string, confirmed_at: datetime, confirmation_sent_at: datetime, unconfirmed_email: string, failed_attempts: integer, unlock_token: string, locked_at: datetime, authentication_token: string, fb_uid: string, fb_token: string, site_id: integer, language_id: integer, region_id: integer, phone: string, first_name: string, last_name: string, birthday: date, created_at: datetime, updated_at: datetime, state: string, alias: string, confirmer_id: integer, gender: integer, custom_properties: hstore, email_is_filled: boolean, viewed_hints: hstore, moderator_id: integer, silent: boolean, clone_source_id: integer), @columns=nil, @aliases=[], @table_alias=nil, @primary_key=nil>, name="id">, @right=1>]
@bopm
Copy link

bopm commented Mar 13, 2013

Installing squeel (1.0.18)
Loading development environment (Rails 3.2.12)
1.9.3-p327-perf :001 > Metric.local.where_values
=> [{:is_global=>false}]

Using squeel (1.0.9)
Loading development environment (Rails 3.2.12)
1.9.3-p327-perf :001 > Metric.local.where_values
=> [#<Arel::Nodes::Equality:0x007faff2d5f008 @right=false, @left=#<struct Arel::Attributes::Attribute relation=#<Arel::Table:0x007faff2d5f0a8 @table_alias=nil, @primary_key=nil, @name="metrics", @engine=Metric(id: integer, type: string, parent_id: integer, position: integer, minimum: integer, maximum: integer, created_at: datetime, updated_at: datetime, is_global: boolean, lft: integer, rgt: integer, depth: integer, hidden_description: text, needles: string, mean_quantity: integer, non_search: boolean, user_fillable: boolean, is_filter: boolean), @columns=nil, @Aliases=[]>, name="is_global">>]

@bopm
Copy link

bopm commented Mar 13, 2013

So scopes doesn't helps in last version of squeel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment