Skip to content

#364 composed_of: Access record information from converter #1436

wants to merge 4 commits into from

6 participants


AR#composed_of can now access the associated record

    class User < ActiveRecord::Base
      composed_of :some_aggregation, ...,  :converter => { |record, values| ... }

Tested against REE and 1.9.2-p180.

@tenderlove tenderlove was assigned Jun 1, 2011

hey there, this was a great addition, however, i noticed something strange - looks like it make a difference in what order the attributes were specified (i guess the one that is being specified in the composed_of, in this case value)

In the examples below, currency field is not populated>"2012-12-5", :end_at=>"2012-12-8",:value=>43,:currency=>"EUR")
:converter => { |record, value, currency| debugger; || 0, currency) }
(rdb:1) pp record
#>"2012-12-5", :end_at=>"2012-12-8",:currency=>"EUR",:value=>43)
:converter => { |record, value, currency| debugger; || 0, currency) }
(rdb:1) pp record



Please apply this patch to the master branch!


@cesario Is this still an issue?

Ruby on Rails member

@cesario This pull request can't be cleanly merged any more. While I don't have the authority to merge it in anyway, clean patches are always faster to get merged than ones that aren't. :)

Ruby on Rails member

If #6743 gets merged, this feature won't be useful.

@pnegri pnegri referenced this pull request Jun 16, 2012

Removing composed_of #6743

@steveklabnik steveklabnik added a commit that closed this pull request Jun 18, 2012
@steveklabnik steveklabnik Removing composed_of from 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)

Instead, you can do something like this:

    def balance
      @balance ||=, currency)

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

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.

Closes #1436
Closes #2084
Closes #3807
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.