Hi again,
I found out, that the following works as well:
Instead of
[:address, {:job=>{:include=>:paygrade}}]
try
{:address => {}, {:job=>{:include=>:paygrade}}}
scho
On 17 Mrz., 15:56, scho <[email protected]> wrote:
> Hi Folks,
>
> I ran into the same problem. Here is my fix, which solved the problem
> (I've added it to my environment.rb):
>
> module ActiveRecord
> module Serialization
> class Serializer
> def add_includes_with_nested_include(&block)
> if include_associations = options.delete(:include)
> base_only_or_except = { :except => options[:except],
> :only => options[:only] }
>
> include_has_options = include_associations.is_a?(Hash)
> associations = include_has_options ?
> include_associations.keys : Array(include_associations)
>
> for association in associations
> association_has_options = association.is_a?(Hash)
> if association_has_options
> macro_association = association.keys.first
> additional_association_options = association
> [macro_association]
> else
> additional_association_options = {}
> macro_association = association
> end
> macro = @record.class.reflect_on_association
> (macro_association).macro
> records = case macro
> when :has_many, :has_and_belongs_to_many
> @record.send(macro_association).to_a
> when :has_one, :belongs_to
> @record.send(macro_association)
> end
> unless records.nil?
> association_options = include_has_options ?
> include_associations[macro_association] : base_only_or_except
> opts = options.merge(association_options).merge
> (additional_association_options)
> yield(macro_association, records, opts)
> end
> end
>
> options[:include] = include_associations
> end
> end
> alias_method_chain :add_includes, :nested_include
> end
> end
> end
>
> If someone wants to commit this to github, more power to you!
>
> scho
>
> On 21 Jan., 04:47, RubyNewbie <[email protected]> wrote:
>
> > The error description above was slightly truncated.
> > The full error is this: You have a nil object when you didn't expect
> > it! The error occurred while evaluating nil.macro
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---