Skip to content

Conversation

franckverrot
Copy link
Contributor

AR#composed_of can now access the associated record

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

Tested against REE and 1.9.2-p180.

@ghost ghost assigned tenderlove Jun 1, 2011
@ilyakatz
Copy link
Contributor

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

Rate.new(:start_at=>"2012-12-5", :end_at=>"2012-12-8",:value=>43,:currency=>"EUR")
/Users/ilyakatz/NetBeansProjects/xxxx/app/models/rate.rb:17
:converter => Proc.new { |record, value, currency| debugger; Money.new(value || 0, currency) }
(rdb:1) pp record
#<Rate id: nil, start_at: "2012-12-05 00:00:00", end_at: "2012-12-08 00:00:00", value: nil, rate_type: nil, min_days: 0, entity_id: nil, created_at: nil, updated_at: nil, currency: nil>

Rate.new(:start_at=>"2012-12-5", :end_at=>"2012-12-8",:currency=>"EUR",:value=>43)
/Users/ilyakatz/NetBeansProjects/xxxx/app/models/rate.rb:17
:converter => Proc.new { |record, value, currency| debugger; Money.new(value || 0, currency) }
(rdb:1) pp record
#<Rate id: nil, start_at: "2012-12-05 00:00:00", end_at: "2012-12-08 00:00:00", value: nil, rate_type: nil, min_days: 0, entity_id: nil, created_at: nil, updated_at: nil, currency: "EUR">

@h0jeZvgoxFepBQ2C
Copy link

Coool!!!

Please apply this patch to the master branch!

@isaacsanders
Copy link
Contributor

@cesario Is this still an issue?

@steveklabnik
Copy link
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. :)

@steveklabnik
Copy link
Member

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

@pnegri pnegri mentioned this pull request Jun 16, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants