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

Don't override accessor if method has attr as column #4012

Closed

Conversation

huoxito
Copy link
Member

@huoxito huoxito commented Nov 24, 2013

Say users want to add a name column in spree_variants. They can't make
use of that attr on a variant instance because Spree would always
delegate that method to a product.

Now it would only delegate if the model doesn't have that column. That
would be all cases in a default scenario.

Possible bad side effects: we're touching the database one more time
when booting the spree engine. That's another issue for heroku users
right now.

Opening this one as a possible suggestion / fix for that use case. Wanted to hear if there's any other better idea or maybe if the use case itself is a bad idea and we shouldn't allow it at all in Spree core. Not really sure what I think about it yet.

Say users want to add a `name` column in spree_variants. They can't make
use of that attr on a variant instance because Spree would always
delegate that method to a product.

Now it would only delegate if the model doesn't have that column. That
would be all cases in a default scenario.

Possible bad side effects: we're touching the database one more time
when booting the spree engine. That's another issue for heroku users
right now.
@@ -37,6 +37,8 @@ def delegate_belongs_to(association, *attrs)
attrs = get_association_column_names(association) if attrs.empty?
attrs.concat get_association_column_names(association) if attrs.delete :defaults
attrs.each do |attr|
next if table_exists? && column_names.include?(attr.to_s)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about attribute_method? instead of this? I think that just checks to see if the attribute method is defined rather than hitting the database. Might do the trick?

@radar
Copy link
Contributor

radar commented Nov 25, 2013

I don't understand what problem this is fixing. When I add a name column to the spree_variants table and set that to a value in the console, I can retrieve it just fine using variant.name...

Steps to reproduce, please!

@radar
Copy link
Contributor

radar commented Nov 25, 2013

Oops, my mistake. I had merged this PR earlier into my branch. I've used attribute_name? and it seems to work alright. Let's see what CI thinks. 👍

@huoxito huoxito closed this in a99a368 Nov 25, 2013
huoxito added a commit that referenced this pull request Nov 25, 2013
Say users want to add a `name` column in spree_variants. They can't make
use of that attr on a variant instance because Spree would always
delegate that method to a product.

Now it would only delegate if the model doesn't have that column. That
would be all cases in a default scenario.

Fixes #4012
huoxito added a commit that referenced this pull request Nov 25, 2013
Say users want to add a `name` column in spree_variants. They can't make
use of that attr on a variant instance because Spree would always
delegate that method to a product.

Now it would only delegate if the model doesn't have that column. That
would be all cases in a default scenario.

Fixes #4012
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

2 participants