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

use attribute name as symbol in hash, without table name, for activerecord scopes #289

Merged
merged 1 commit into from Feb 9, 2016

Conversation

scambra
Copy link
Contributor

@scambra scambra commented Dec 3, 2015

I have self.table_name = 'database.table' in my AASM model, because I do sharding and change database connected on ActiveRecord::Base on every request, but for AASM model I want to use the main database always, so I set in the table name so I don't need to establish new connection.

However, setting conditions with "#{@klass.table_name}.#{@klass.aasm(@name).attribute_name}" generates wrong SQL:

`database`.`table_name.status`, instead of `database`.`table_name`.`status`

If conditions uses column name as symbol, such as {:status => name.to_s}, activerecord generates right SQL, including table name (and database in my case).

@alto alto self-assigned this Dec 8, 2015
@alto
Copy link
Member

alto commented Dec 8, 2015

@scambra Could you explain what you mean with "database.table_name.status, instead of database.table_name.status", please?

@scambra
Copy link
Contributor Author

scambra commented Dec 10, 2015

I didn't see ` was removed on my comment, it should be clearer now

@alto
Copy link
Member

alto commented Dec 11, 2015

Hmm, it wasn't about the formatting, more about the content. You say, it generates wrong SQL X, and it should provide rather Y. But in your example, X and Y are the same.

@alto
Copy link
Member

alto commented Dec 11, 2015

Ah no, I'm wrong. Sorry. Now it's clearer.

@alto
Copy link
Member

alto commented Feb 5, 2016

@scambra Sorry, it's been a while. Do you mind merging the current master back into your fork?

@scambra scambra reopened this Feb 5, 2016
@scambra
Copy link
Contributor Author

scambra commented Feb 5, 2016

rebased

@alto
Copy link
Member

alto commented Feb 9, 2016

@scambra Sweet, thanks a lot!

alto added a commit that referenced this pull request Feb 9, 2016
use attribute name as symbol in hash, without table name, for activerecord scopes
@alto alto merged commit f98d734 into aasm:master Feb 9, 2016
alto added a commit that referenced this pull request Feb 9, 2016
@scambra
Copy link
Contributor Author

scambra commented Feb 9, 2016

Thanks

@alto
Copy link
Member

alto commented Feb 22, 2016

I just released version 4.9.0 including the change.

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

Successfully merging this pull request may close these issues.

None yet

2 participants