Skip to content

Instantly share code, notes, and snippets.

@klochner
Created December 14, 2010 00:51
Show Gist options
  • Save klochner/739852 to your computer and use it in GitHub Desktop.
Save klochner/739852 to your computer and use it in GitHub Desktop.
#models/user.rb
class User < ActiveRecord::Base
has_one :address
named_scope :with_city_info,
:joins=>:address,
:select="users.*, addresses.city as user_city"
end
#models/address.rb
class Address < ActiveRecord::Base
belongs_to :user
end
#users controller
def locations
@users = User.with_city_info
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment