Skip to content

Instantly share code, notes, and snippets.

@grobie
Created December 2, 2009 14:02
Show Gist options
  • Save grobie/247213 to your computer and use it in GitHub Desktop.
Save grobie/247213 to your computer and use it in GitHub Desktop.
script/generate model User code:integer
script/generate model Address user:references
script/console
>> User.all
User Load (0.4ms) SELECT * FROM `users`
=> [#<User id: 1, code: 333, created_at: "2009-12-01 23:47:29", updated_at: "2009-12-01 23:47:29">,
#<User id: 2, code: 999, created_at: "2009-12-01 23:47:34", updated_at: "2009-12-01 23:47:34">,
#<User id: 3, code: 1000, created_at: "2009-12-01 23:47:36", updated_at: "2009-12-01 23:47:36">]
>> User.search 333
Querying Sphinx: 333
User Load (0.3ms) SELECT * FROM `users` WHERE (`users`.`id` IN (1))
=> [#<User id: 1, code: 333, created_at: "2009-12-01 23:47:29", updated_at: "2009-12-01 23:47:29">]
>> User.search 999
Querying Sphinx: 999
User Load (0.3ms) SELECT * FROM `users` WHERE (`users`.`id` IN (2))
=> [#<User id: 2, code: 999, created_at: "2009-12-01 23:47:34", updated_at: "2009-12-01 23:47:34">]
>> User.search 1000
Querying Sphinx: 1000
=> []
id code sphinx_internal_id class_crc subclass_crcs sphinx_deleted addresses_ids
1 333 1 765557111 765557111 0 0
2 999 2 765557111 765557111 0 0
3 1000 3 765557111 765557111 0 0
class User < ActiveRecord::Base
has_many :addresses
define_index do
indexes :code
has addresses(:id), :as => :addresses_ids
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment