with_role function in Resource roles querying gives ActiveRecord::StatementInvalid: Mysql2::Error #65

Closed
zaidakram opened this Issue Apr 25, 2012 · 6 comments

Comments

Projects
None yet
5 participants

I resolved it by editing rolify / lib / rolify / adapters / active_record / resource_adapter.rb

and replaced line no. 7 by

resources = relation.joins("INNER JOIN #{roles_table} ON #{roles_table}.resource_type = '#{relation.to_s}'")

i.e replacing double quotes with backticks.

Member

EppO commented Apr 25, 2012

Hi, thanks for the bug report. I've tested rolify only with sqlite and postgresql so far, I was not aware there was some quotes issue with mysql. Can you submit a pull request for your change ? I will try on my side if it doesn't break other DBs.

EppO was assigned Apr 25, 2012

Member

EppO commented Apr 25, 2012

Weird, I don't see your patch as a PR on github... is it a bug ? it's like you tried to commit directly in my repo in my point of view but I don't see the change in it, just the commit... can you try the PR again ?

@tonymarschall tonymarschall pushed a commit to tonymarschall/rolify that referenced this issue Apr 26, 2012

Tony Marschall added patch from issue #65 provided by @zaidakram a5edd0e

Mh, strange. I have send a pr. Since i am pretty new to git i do not understand why there is the second change with the newline issue. Hope its ok.

Member

EppO commented Apr 26, 2012

Thanks, I got it now. Don't worry, the newline thing is not a big deal.

EppO closed this in da1ec59 Apr 26, 2012

stonehz commented Jul 19, 2012

I had a similar problem using rolify with postgres ...
Check the example to see how i managed to fix it:

u = User.last
u.add_role :manager, Product.last

Now if you try:

Product.with_role(:manager, u)
you get : ActiveRecord::StatementInvalid: PG::Error: ERROR: column roles.manager does not exist

Then, I changed to this and works:
Product.with_role("manager", u)

I had the same problem with postgres recently. Changing the :name_of_the_role to "name_of_the_role" in the query works fine.

EppO was unassigned by zaidakram Jul 3, 2014

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