Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #4811 from prisma/OneRelationIsNullBug
Browse files Browse the repository at this point in the history
One relation is null bug
  • Loading branch information
do4gr authored Aug 20, 2019
2 parents b77460f + 250243b commit 30786b5
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ trait FilterConditionBuilder extends BuilderBase {
val select = sql
.select(relationColumn(relationField))
.from(relationTable(relation))
.where(relationColumn(relationField).isNotNull)

modelIdColumn(alias, relationField.relatedModel_!).notIn(select)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package com.prisma.api.filters.nonEmbedded

import com.prisma.api.ApiSpecBase
import com.prisma.shared.models.ConnectorCapability
import com.prisma.shared.models.ConnectorCapability.{JoinRelationLinksCapability, Prisma2Capability}
import com.prisma.shared.schema_dsl.SchemaDsl
import org.scalatest._

class RelationIsNullSpec extends FlatSpec with Matchers with ApiSpecBase {
override def runOnlyForCapabilities = Set(JoinRelationLinksCapability)
override def doNotRunForCapabilities = Set(Prisma2Capability)

val project = SchemaDsl.fromStringV11() {
"""
|type Message {
| id: ID! @id
| image: Image @relation(link: INLINE, name: "MessageImageRelation")
| messageName: String
|}
|
|type Image {
| id: ID! @id
| message: Message @relation(name: "MessageImageRelation")
| imageName: String
|}
"""
}

override protected def beforeAll(): Unit = {
super.beforeAll()
database.setup(project)
}

override def beforeEach() = {
super.beforeEach()
database.truncateProjectTables(project)

// add data
server.query(
"""mutation {createMessage(
| data: {
| messageName: "message 1",
| }
|){messageName}}""",
project = project
)

server.query(
"""mutation {createMessage(
| data: {
| messageName: "message 2",
| image:{create:{imageName:"image 1"}}
| }
|){messageName}}""",
project = project
)

server.query(
"""mutation {createImage(
| data: {
| imageName: "image 2"
| }
|){imageName}}""",
project = project
)

}

"Filtering on whether a relation is null" should "work" in {
server
.query(
query = """query {
| images(where: { message: null }) {
| imageName
| }
|}""",
project = project
)
.toString should be("""{"data":{"images":[{"imageName":"image 2"}]}}""")
}

"Filtering on whether a relation is null" should "work 2" in {
server
.query(
query = """query {
| messages(where: { image: null }) {
| messageName
| }
|}""",
project = project
)
.toString should be("""{"data":{"messages":[{"messageName":"message 1"}]}}""")
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.prisma.shared.models

import com.prisma.shared.models.ConnectorCapability.Prisma2Capability
import com.prisma.utils.boolean.BooleanUtils
import enumeratum.{EnumEntry, Enum => Enumeratum}

Expand Down Expand Up @@ -35,6 +36,8 @@ object ConnectorCapability extends Enumeratum[ConnectorCapability] {
object IntIdCapability extends IdCapability
object UuidIdCapability extends IdCapability
object IdSequenceCapability extends IdCapability

object Prisma2Capability extends ConnectorCapability
}

case class ConnectorCapabilities(capabilities: Set[ConnectorCapability]) {
Expand All @@ -58,8 +61,10 @@ object ConnectorCapabilities extends BooleanUtils {
def apply(capabilities: ConnectorCapability*): ConnectorCapabilities = ConnectorCapabilities(Set(capabilities: _*))

lazy val sqliteNative: ConnectorCapabilities = {
val filteredCapas = sqliteJdbcPrototype.capabilities.filter(_ != TransactionalExecutionCapability)
ConnectorCapabilities(filteredCapas)
val filteredCapas = sqliteJdbcPrototype.capabilities
.filter(_ != TransactionalExecutionCapability)
.filter(_ != NodeQueryCapability)
ConnectorCapabilities(Set(Prisma2Capability) ++ filteredCapas)
}

lazy val sqliteJdbcPrototype: ConnectorCapabilities = {
Expand Down

0 comments on commit 30786b5

Please sign in to comment.