stalniy/ucast

interpret from @ucast/sql/objection does not take knexSnakeCaseMappers into account

Closed this issue · 2 comments

Hello,

I am testing the casl / objection integration for a project based on this gist. Since @ucast/objection is deprecated, i converted the code to use interpret from @ucast/sql/objection. But the code is creating a different sql command now - i do use knexSnakeCaseMappers for objection.

abilities

    allow(
      ['read', 'update', 'replace', 'delete'],
      [AccountModel],
      {
        'accountOwner.id': user.id,
      }
    );

    allow(
      ['read', 'update', 'replace', 'delete'],
      [AwsAccountModel],
      {
        'technicalContact.id': user.id,
      }
    );

sql command before (technical_contact):

select "aws_accounts".* from "aws_accounts"
inner join "users" as "technical_contact" on "technical_contact"."id" = CAST("aws_accounts"."data"#>>'{TechnicalContact}' AS text) 
inner join "users" as "account_owner" on "account_owner"."id" = CAST("aws_accounts"."data"#>>'{AccountOwner}' AS text)
where (("technical_contact"."id" = $1 or "account_owner"."id" = $2))

sql command now (technicalContact):

select "aws_accounts".* from "aws_accounts" 
inner join "users" as "technical_contact" on "technical_contact"."id" = CAST("aws_accounts"."data"#>>'{TechnicalContact}' AS text)
inner join "users" as "account_owner" on "account_owner"."id" = CAST("aws_accounts"."data"#>>'{AccountOwner}' AS text) 
where ("technicalContact"."id" = $1 or "accountOwner"."id" = $2)

Please delete this issue, if it is in the wrong place or irrelevant.

Best Christian

Hello,

The place for the issue is correct :) Sorry for being inactive for so long time. Quite busy family stuff.

Well, this is expected because @ucast/sql/objection doesn't use knex to generate query. It's much faster and easier to generate a raw sql string than a knex query builder instance. However, there is an localField and foreignField options in @ucast/sql which I recently added in order to customize references to own columns and columns of related entities. I think they can be used to achieve what you want.

But they are not available at ORM integration level. I plan to release CASL v5 in the next couple days, all is ready to make release, finally :) Then I will get back to @ucast/sql and its improvements.

No worries, it was just something I recognized during testing. Looking forward to CASL v5! I will try again if you have a new release available.