Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Cannot save user_ids to an instance of Spree::Promotion::Rules::User #3885
I want to create a list of Users that a promotion applies to. So, I setup a Promotion that requires specific Users in the Admin Tool.
However, I cannot directly pass user_ids or call user_ids_string setter on Spree::Promotion::Rules::User because the association is not associated with the Spree::User.table_name.
This causes it to be impossible to add Users to a specific Spree::Promotion::Rules::User list instance unless the user_id also happens to equal the Spree::Promotion::Rules::User.id resulting in a "Promotion not found" error in the promotions admin tool.
Lets say I instantiate a rule list
Then populate it out
This rule list has some methods that can be found under spree_core/app/models/spree/promotion/rules/
That's pretty straight forward...
So if I do:
It should look up Spree::User.id: 1 and Spree::User.id: 3 and upon verifying their existence, add them to the string that the setter uses to populate Spree::Promotion::Rules::User.user_ids,
but when i do it:
But, if I specify the id of the rule_list.id itself....
So for some reason it thinks that the user_ids should equal only the Spree::Promotion::Rules::User.ids
So to prove to myself that this is in fact what is happening I instead try to directly set user_ids of the rule_list using 2 verified user_ids: 1, 3 and the Spree::Promotion::Rules::User.id itself, 7.
So it does find the 7, but not the 1 and 3. Something about the Spree::Promotion::Rules::User.user_ids attribute erroneously expects the table it wants to be "spree_promotion_rules" instead of "spree_promotion_rules_users".
Spree Version: 2.1.1
source 'https://rubygems.org' ruby '2.0.0' gem 'rails', '4.0.0' gem 'pg' gem 'sass-rails', '~> 4.0.0' gem 'uglifier', '>= 1.3.0' gem 'coffee-rails', '~> 4.0.0' gem 'jquery-rails' gem 'turbolinks' gem 'jbuilder', '~> 1.2' group :doc do gem 'sdoc', require: false end gem 'spree', '2.1.1' gem 'spree_gateway', :git => 'https://github.com/spree/spree_gateway.git', :branch => '2-1-stable' gem 'spree_auth_devise', :git => 'https://github.com/spree/spree_auth_devise.git', :branch => '2-1-stable'
This comment has been minimized.
This comment has been minimized.Show comment Hide comment
I took a look at this today and it's actually quite difficult to solve. It's been about an hour now and I don't have a solid solution to the problem. However: I do know what's causing it, so maybe that can be of some help to a future investigator.
Maybe it's a worthwhile tradeoff, or maybe not. Right now, I am conflicted about the decision on this one.