clowne-rb/clowne

Association couldn't be found, Rails 4.1.8

Closed this issue · 3 comments

I have a very simple two model scenario with a has_many association in the model that I want to clone. So I declared

class PostsCloner < Clowne::Cloner
  adapter :active_record
  include_association :comments
end

The clone attempt results in an exception: Clowne::Adapters::ActiveRecord::Resolvers::UnknownAssociation: Association comments couldn't be found for User

It appears that this code is attempting to resolve the relation using a string index into ...reflections, but the reflections hash uses symbols.

def call(source, record, declaration, adapter:, params:, **_options)
reflection = source.class.reflections[declaration.name.to_s]
if reflection.nil?
raise UnknownAssociation,
"Association #{declaration.name} couldn't be found for #{source.class}"
end

Maybe this is a compatibility issue with Rails 4.1.8, Ruby 2.3

PR #41 submitted to address this

Closed because of #41 (comment)

Having the same issue on Rails 5.2.4.5 -- will dig further to see if I can improve the PR.