Code Monkey home page Code Monkey logo

Comments (6)

npadgett avatar npadgett commented on May 9, 2024

I am using cancancan 1.8.4.

from cancancan.

bryanrite avatar bryanrite commented on May 9, 2024

Would someone be able to double check this is still occurring in 1.9.2? We've done some work on the way models are referenced. Thanks!

from cancancan.

npadgett avatar npadgett commented on May 9, 2024

bryanrite,

This has been fixed. Thanks for your help.

> Employee.accessible_by(Ability.new(user)).to_sql
 => "SELECT `employees`.`id` AS t0_r0, `employees`.`company_id` AS t0_r1, 
`employees`.`permissions` AS t0_r2, `employees`.`user_id` AS t0_r3, `employees`.`name` AS t0_r4, 
`companies`.`id` AS t1_r0, `companies`.`user_id` AS t1_r1, `companies`.`name` AS t1_r2, 
`employees_companies`.`id` AS t2_r0, `employees_companies`.`company_id` AS t2_r1, 
`employees_companies`.`permissions` AS t2_r2, `employees_companies`.`user_id` AS t2_r3, 
`employees_companies`.`name` AS t2_r4 FROM `employees` LEFT OUTER JOIN `companies` ON 
`companies`.`id` = `employees`.`company_id` LEFT OUTER JOIN `employees` 
`employees_companies` ON `employees_companies`.`company_id` = `companies`.`id` WHERE 
`employees`.`user_id` = 1" 

> Customer.accessible_by(Ability.new(user)).to_sql
 => "SELECT `customers`.`id` AS t0_r0, `customers`.`company_id` AS t0_r1, `customers`.`user_id` AS 
t0_r2, `customers`.`name` AS t0_r3, `companies`.`id` AS t1_r0, `companies`.`user_id` AS t1_r1, 
`companies`.`name` AS t1_r2, `employees`.`id` AS t2_r0, `employees`.`company_id` AS t2_r1, 
`employees`.`permissions` AS t2_r2, `employees`.`user_id` AS t2_r3, `employees`.`name` AS t2_r4 
FROM `customers` LEFT OUTER JOIN `companies` ON `companies`.`id` = `customers`.`company_id` 
LEFT OUTER JOIN `employees` ON `employees`.`company_id` = `companies`.`id` WHERE 
`employees`.`user_id` = 1"

from cancancan.

freemanoid avatar freemanoid commented on May 9, 2024

@bryanrite I have the same issue on 1.9.2, rails 3.2. Do you have an idea how I can figure it out?

from cancancan.

freemanoid avatar freemanoid commented on May 9, 2024

And on develop branch (c2c3c93)

from cancancan.

freemanoid avatar freemanoid commented on May 9, 2024

Actually, I'm not using self-referential models but I want to get correct sql by Payment.accessible_by(current_ability).to_sql when there is a rule with some joins like this

can [:index], Payment, loan: { customer: { lenders: { id: agency_ids } } } 

But I'm getting

SELECT `payments`.* FROM `payments`  WHERE `lenders`.`id` IN (1,2)

from cancancan.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.