Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate the use of singleton classes on CPK relations. #169

Merged
merged 1 commit into from Nov 2, 2013

Conversation

justinweiss
Copy link
Contributor

Previously, CPK overrode ActiveRecord::Relation on creation and
injected a singleton class into the object hierarchy, which caused the
relation (and the model holding it) to be undumpable.

I've moved the overridden methods into their own class, and overrode
ActiveRecord::Relation#new to act as a factory method, returning either
an ActiveRecord::Relation or a CompositePrimaryKeys::CompositeRelation
as needed.

Previously, CPK overrode ActiveRecord::Relation on creation and
injected a singleton class into the object hierarchy, which caused the
relation (and the model holding it) to be undumpable.

I've moved the overridden methods into their own class, and overrode
ActiveRecord::Relation#new to act as a factory method, returning either
an ActiveRecord::Relation or a CompositePrimaryKeys::CompositeRelation
as needed.
@justinweiss
Copy link
Contributor Author

This resolves #116.

@cfis
Copy link
Contributor

cfis commented Oct 14, 2013

Thanks for the patch - looks like a good idea. Will try and review it this weekend.

@pdf
Copy link

pdf commented Oct 22, 2013

It's a great idea - just spent hours tracking down the source of my unmarshallable objects. Working fine with @justinweiss's patch.

cfis added a commit that referenced this pull request Nov 2, 2013
Eliminate the use of singleton classes on CPK relations.
@cfis cfis merged commit 10c705b into composite-primary-keys:master Nov 2, 2013
@cfis
Copy link
Contributor

cfis commented Nov 2, 2013

I am reverting this commit because it breaks a ton of tests. To be exact:

127 tests, 127 assertions, 8 failures, 74 errors, 0 skips

Unfortunately this approach will not work due to code in relation/delegation.rb:

  def new(klass, *args)
    relation = relation_class_for(klass).allocate
    relation.__send__(:initialize, klass, *args)
    relation
  end

By overriding the picking of the class, all relations are broken by this pull request.

@justinweiss
Copy link
Contributor Author

Sorry about that. I’m really not sure how I missed testing this under Rails 4, since it clearly doesn’t work with some of the activerecord changes. I don’t have any Rails 4 projects yet, so most of the writing and testing of this patch happened under 3.2.

I’ll take another look, it shouldn’t be too hard to fix.

On Nov 2, 2013, at 4:46 PM, Charlie Savage notifications@github.com wrote:

I am reverting this commit because it breaks a ton of tests. To be exact:

127 tests, 127 assertions, 8 failures, 74 errors, 0 skips

Unfortunately this approach will not work due to code in relation/delegation.rb:

def new(klass, *args)
relation = relation_class_for(klass).allocate
relation.send(:initialize, klass, *args)
relation
end
By overriding the picking of the class, all relations are broken by this pull request.


Reply to this email directly or view it on GitHub.

@cfis
Copy link
Contributor

cfis commented Nov 3, 2013

Sounds good...I think you're right on the tests aren't looking good on Rails 4, so some of those failures aren't due to this commit.

@justinweiss
Copy link
Contributor Author

I almost had this working under Rails 4.0.1, but the code I was hooking is getting rewritten again: https://github.com/rails/rails/commits/master/activerecord/lib/active_record/relation/delegation.rb. I'm going to hold off looking at this until the changes settle down.

@cfis
Copy link
Contributor

cfis commented Nov 24, 2013

Ok, sounds good, will cut a new release then.

@bdurand
Copy link

bdurand commented Sep 30, 2014

Any updates on this fix? I'm still running into the problem and hopefully the upstream changes in ActiveRecord 4 have settled down by now.

@justinweiss
Copy link
Contributor Author

Nope -- we've stopped using composite keys, so I haven't invested any more time in this. If someone wants to try to do something with the code, though, I'd be happy to answer questions about it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants