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
Breaks first_or_create (conflict with Squeel) #176
Comments
Also, I should add that the only thing I have to do to make this work is remove composite_primary_keys from the Gemfile. |
I set up a new rails project so I could create a bare minimum example that reproduces the problem. Turns out it is a conflict between the source 'https://rubygems.org'
ruby '1.9.3'
gem 'rails', ' 4.0.2'
gem 'mysql2'
gem 'squeel'
gem 'composite_primary_keys' The only other thing I have in the project is a single empty class Role < ActiveRecord::Base
end and this is the problem run in the rails console: Role.where(name: 'test10').first_or_create
Role Load (0.2ms) SELECT `roles`.* FROM `roles` WHERE `roles`.`name` = 'test10' ORDER BY `roles`.`id` ASC LIMIT 1
(0.1ms) BEGIN
SQL (0.2ms) INSERT INTO `roles` (`created_at`, `updated_at`) VALUES ('2014-01-04 19:12:12', '2014-01-04 19:12:12')
(0.3ms) COMMIT The problem goes away if I remove either the |
Update: two gems together somehow manage to clear |
Update: it seems like it might be caused by both gems mucking with the |
I think I have found a workaround, but I'm out of time, so I'll post it later. |
Ok, so I've got a workaround for now. It turns out that They both replace the ActiveRecord method However, it turns out that Unfortunately that is impossible without patching. For now, I am using a forked version of To the maintainers/authors: how can we add compatibility with I'll leave this issue open for now because what I have is only a hack work around, I would like to find a real, more permanent solution. |
Any progress on this front? I am working on a project that already uses composite_primary_keys, and would like to add the squeel gem as well, but it's breaking occurrences of first_or_create. |
I haven't heard anything. I wish I had, but for now you are welcome to use my fork. |
Want to submit a patch? |
I would be happy to, the only problem, as I said in my last big comment is I don't know the best way to solve this problem. To quote myself:
|
Yeah, hard to say since I've never used squeel. I do notice though thatsqueel is no longer maintained, so maybe just stick with your workaround? |
I'm sure someone will pick up squeel, it's too good to let die (if no one else does, my company will have to, it's pretty mission critical to us). Is there a way I can modify the patching of where_values_hash to do it at library load time instead of initialize time? Then I could fix it by making sure Squeel was included last in the Gemfile. It seem non-performant to patch this method on every object. |
I don't remember why it was done the current way, would be nicer to do it just once like said. I'll leave this to you to explore further if you want, any time I have on CPK I think needs to focus on AR 4.1 |
Ok, I'm going to go ahead and close this. |
I'll take time to give more detail tomorrow, but for now, I'm pretty sure composite-primary-keys is breaking ActiveRecord's first_or_create. I'm running ActiveRecord 4.0.2 and the latest composite-primary-keys (6.0.1)
I've got an empty class:
and I run the command:
Role.where(:name => 'practice').first_or_create
which generates the following sql:
So the find works, but not the create.
Side note: this works fine
Role.new(:name => 'practice').save
, generating the following sql:Any ideas?
The text was updated successfully, but these errors were encountered: