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

ORM joins functionality doesn't include schema name in primary table from clause #438

Open
gavares opened this issue May 22, 2022 · 1 comment

Comments

@gavares
Copy link

gavares commented May 22, 2022

Given two entities

case class Permission(id: Long, subjectId: Subject) extends SkinnyRecord[Permission] {
 override def skinnyCRUDMapper: CRUDFeatureWithId[Long, Permission] = Permission
}

object Permission extends SkinnyCRUDMapper[Permission] {
  override val schemaName = "my_schema"
  override def defaultAlias = createAlias("perm")
  override lazy val columns = autoColumns[Permission]("subject")

  val subject = belongsToWithFk[Subject](
    right = Subject,
    fk = column.subjectId.value,
    merge = (p, s) => p.copy(subject = s.get)
  )

}

And a subject entity:

case class Subject(entityType: String, subjectKey: String, id: Long = -1)
    extends SkinnyRecord[Subject] {
  override def skinnyCRUDMapper: CRUDFeatureWithId[Long, Subject] = Subject
}

object OrgSubject extends SkinnyCRUDMapper[Subject] {
  override val schemaName = Permission.schemaName
  override val tableName = "org_subject"
  override lazy val defaultAlias = createAlias("sub")
  override lazy val columns = autoColumns[Subject]()
  override def useAutoIncrementPrimaryKey = true

Attemping to run:

  Permission.withColumns { p => 
      Permission.joins(Permission.subject).where.eq(p.id, 1)
  }

Generates a query that does not include the schema name for the Permission table but does include the schema name for the Subject table. This causes queries to fail due to table not found:

   select perm.id, sub.entity_type, sub.subject_key, sub.id from permission as perm left join my_schema.subject  as sub on perm.subject_id = sub.id where perm.id = 1

In the query above, the from clause should reference the permission table as my_schema.permission instead of just permission.

This behavior happens for all the entity relations I've tried: hasOne, hasMany, belongsTo

I'm currently using skinny-orm: 4.0.0

@seratch
Copy link
Member

seratch commented Jun 5, 2022

If I remember correctly, this kind of issue tends to depend on the underlying JDBC driver's behavior. I am open to merging external contributions to fix it as long as the change does not bring any breaking changes to existing apps.

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

No branches or pull requests

2 participants