Skip to content

Commit

Permalink
README file
Browse files Browse the repository at this point in the history
  • Loading branch information
pahanix committed Jan 9, 2010
1 parent 50322f5 commit 6fbcdb7
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
1 change: 0 additions & 1 deletion README

This file was deleted.

57 changes: 57 additions & 0 deletions README.mdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Delegates Attributes To

Simple association attributes delegator plugin. It automatically delegates association attributes accessors to a model. It also supports ActiveRecord::Dirty check for delegated attributes.

[Original idea](http:https://www.kellerandfaber.com/writing/delegate_belongs_to-delegating-to-associations-in-rails) of the [plugin](http:https://github.com/faber/delegate\_belongs\_to)

class Contact
# firstname
# lastname
end

class Profile
# about
# hobby
end

class User
belongs_to :contact
delegates_attributes_to :contact

# or
# delegate_belong_to :contact

has_one :profile
delegates_attributes_to :profile
# or
# delegate_has_one :profile
end

# Full ActiveRecord::Dirty check support for delegated attributes

u = User.first

u.firstname # => "Jonh"
u.firstname_changed? # => false
u.changed? # => false
u.firstname = 'Bob'
u.firstname # => "Bob"
u.firstname_was # => "Jonh"
u.firstname_changed? # => true
u.changed? # => true
u.contact.changed? # => true

u = User.last

u.changed? # => false
u.profile.about = "Bob"
u.chaged? # => true

u = User.last

u.chaged? # => false
u.about = "Bob"
u.chaged? # => true
u.profile.chaged? # => true

0 comments on commit 6fbcdb7

Please sign in to comment.