Skip to content

Instantly share code, notes, and snippets.

@rduarte
Created June 7, 2010 22:40
Show Gist options
  • Save rduarte/429293 to your computer and use it in GitHub Desktop.
Save rduarte/429293 to your computer and use it in GitHub Desktop.
# app/models/customer.rb
class Customer < ActiveRecord::Base
has_one :user
delegate :login, :login=, :password, :password=, :to => :user
end
# app/models/user.rb
class User < ActiveRecord::Base
belongs_to :customer
end
c = Customer.last
=> #<Customer id: 1, name: "Ricardo", created_at: "2009-07-19 00:50:01", updated_at: "2009-07-19 00:50:01">
c.user
=> #<User id: 1, login: "ricardo", password: "123456", customer_id: 1, created_at: "2009-07-19 00:50:36", updated_at: "2009-07-19 00:50:53">
c.login
=> "ricardo"
c.password
=> "123456"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment