ryanb / cancan

Authorization Gem for Ruby on Rails.
MIT License
6.26k stars 783 forks source link

Not pluralizing the join call? #781

Open runemadsen opened 11 years ago

runemadsen commented 11 years ago

I have these classes

class Press
  has_many :books
end

class Book
  belongs_to :press
end

class Permission
  belongs_to :book
end

I'm defining this ability:

can :manage, Permission, :book => {:press_id => press_id}

And it throws this error:

SQLite3::SQLException: no such column: book.press_id: SELECT "book_permissions".* FROM "book_permissions" INNER JOIN "books" ON "books"."id" = "book_permissions"."book_id" WHERE "book_permissions"."book_id" = 1 AND "book"."press_id" = 1

It seems like it's not pluralizing the last "book"."press_id" = 1.

Is this me, or is this a bug in CanCan?

aosalias commented 11 years ago

Looks like it is pluralizing the join but not the column lookup. I am having the same issue.

Channel belongs to account. Account has column publishing_tab. Getting this sql error:

Mysql2::Error: Unknown column 'account.publishing_tab' in 'where clause': SELECT DISTINCT channels.* FROM channels INNER JOIN accounts ON accounts.id = channels.account_id INNER JOIN user_channels ON user_channels.channel_id = channels.id INNER JOIN capabilities ON capabilities.id = user_channels.capability_id WHERE channels.account_id = 1 AND account.publishing_tab = 'show'

the8472 commented 11 years ago

this is probably the same as #646

victorbv commented 11 years ago

Try this:

can :manage, Permission, :book => { :id => press.book_ids }
chorstikus commented 11 years ago

Got the same error:

SELECT "projects".* FROM "projects" INNER JOIN "groups" ON "groups"."id" = "projects"."group_id" WHERE "projects"."owner_id" = 1 AND "group"."owner_id" = 1 ORDER BY progress DESC

not pluralizing "group" in WHERE clause

Ability looks like this:

can :manage, Project, :owner_id => user.id, :group => { :owner_id => user.id }
xhoy commented 10 years ago

Thanks for your submission! The ryanb/cancan repository has been inactive since Sep 06, 2013. Since only Ryan himself has commit permissions, the CanCan project is on a standstill.

CanCan has many open issues, including missing support for Rails 4. To keep CanCan alive, an active fork exists at cancancommunity/cancancan. The new gem is cancancan. More info is available at #994.

If your pull request or issue is still applicable, it would be really appreciated if you resubmit it to CanCanCan.

We hope to see you on the other side!