Hi,

I have an unusual use-case where I need to override a has_many
accessor to return an array of results depending on some the value of
a class variable. I've tried several solutions, the closest to success
using the extension option:

[code]
has_many :meta_associations, :as => :meta_extendable do
          # Find any meta_associations that are joined to this
activerecord instance
          def meta_associations(*args)
            options = args.extract_options!

            if proxy_owner.class.applicable_type ==
proxy_owner.class.name
              options[:conditions] ||= { :meta_extendable_id =>
proxy_owner.id,
                                         :meta_extendable_type =>
proxy_owner.class.applicable_type }
            else
              options[:conditions] ||= { :meta_extendable_id =>
proxy_owner.send
(proxy_owner.class.applicable_type_foreign_key.to_sym),
                                         :meta_extendable_type =>
proxy_owner.class.applicable_type }
            end

            MetaAssociation.find(args.first, options)
          end

        end
[/code]

However, this just gives me an
instance.meta_associations.meta_associations method, rather than
overriding the default instance.meta_associations. Is this possible,
or should I forget using :has_many and manually write all the
collection accessors/mutators?

Thanks,
Chris
--
www.chrisblunt.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to