Deprecate composed of #6742

Merged
merged 1 commit into from Jun 18, 2012

Conversation

Projects
None yet
2 participants
Member

steveklabnik commented Jun 15, 2012

composed_of is a complicated feature that's rarely used. So let's deprecate it. And remove it in Rails 4.

Related: #6743

/cc @jonleighton @tenderlove

@steveklabnik steveklabnik referenced this pull request Jun 15, 2012

Merged

Removing composed_of #6743

Owner

rafaelfranca commented Jun 18, 2012

Now, the same thing for this one.

Member

steveklabnik commented Jun 18, 2012

Updated.

Owner

rafaelfranca commented Jun 18, 2012

CHANGELOG entry

Deprecating composed_of in ActiveRecord
This feature adds a lot of complication to ActiveRecord for dubious
value. Let's talk about what it does currently:

class Customer < ActiveRecord::Base
  composed_of :balance, :class_name => "Money", :mapping => %w(balance
amount)
end

Instead, you can do something like this:

    def balance
      @balance ||= Money.new(value, currency)
    end

    def balance=(balance)
      self[:value] = balance.value
      self[:currency] = balance.currency
      @balance = balance
    end

Since that's fairly easy code to write, and doesn't need anything
extra from the framework, if you use composed_of today, you'll
have to add accessors/mutators like that.

This feature will be removed in Rails 4.
Member

steveklabnik commented Jun 18, 2012

Pushed.

rafaelfranca added a commit that referenced this pull request Jun 18, 2012

@rafaelfranca rafaelfranca merged commit ffcecf2 into rails:3-2-stable Jun 18, 2012

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