-
Notifications
You must be signed in to change notification settings - Fork 616
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Double check for a collection to be present in the mapping witho…
…ut directional prefix. This is a direct follow up on #2918, in which we added the suffix to the collection names. That change didn’t take custom queries into account and people are most likely still using the known pattern of `source_REL_target` and I would like to not break them. Therefor, we check now in the values list if a collection without suffix exists if we didn’t find one with and if so, use that. This fixes #2963.
- Loading branch information
1 parent
8d74680
commit 9b23c03
Showing
4 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/test/java/org/springframework/data/neo4j/integration/issues/gh2963/MyModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright 2011-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.data.neo4j.integration.issues.gh2963; | ||
|
||
import org.springframework.data.neo4j.core.schema.GeneratedValue; | ||
import org.springframework.data.neo4j.core.schema.Id; | ||
import org.springframework.data.neo4j.core.schema.Node; | ||
import org.springframework.data.neo4j.core.schema.Relationship; | ||
import org.springframework.data.neo4j.core.support.UUIDStringGenerator; | ||
|
||
/** | ||
* @author Andreas Rümpel | ||
* @author Michael J. Simons | ||
*/ | ||
@Node | ||
public class MyModel { | ||
@Id | ||
@GeneratedValue(generatorClass = UUIDStringGenerator.class) | ||
private String uuid; | ||
|
||
private String name; | ||
|
||
@Relationship(value = "REL_TO_MY_NESTED_MODEL") | ||
private MyModel myNestedModel; | ||
|
||
public MyModel getMyNestedModel() { | ||
return myNestedModel; | ||
} | ||
|
||
public void setMyNestedModel(MyModel myNestedModel) { | ||
this.myNestedModel = myNestedModel; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getUuid() { | ||
return uuid; | ||
} | ||
|
||
public void setUuid(String uuid) { | ||
this.uuid = uuid; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/test/java/org/springframework/data/neo4j/integration/issues/gh2963/MyRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2011-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.data.neo4j.integration.issues.gh2963; | ||
|
||
import java.util.Optional; | ||
|
||
import org.springframework.data.neo4j.repository.query.Query; | ||
import org.springframework.data.repository.CrudRepository; | ||
|
||
/** | ||
* @author Andreas Rümpel | ||
* @author Michael J. Simons | ||
*/ | ||
public interface MyRepository extends CrudRepository<MyModel, String> { | ||
|
||
@Query(""" | ||
MATCH (root:MyModel {uuid: $uuid}) | ||
RETURN root { | ||
.*, MyModel_REL_TO_MY_NESTED_MODEL_MyModel: [ | ||
(root)-[:REL_TO_MY_NESTED_MODEL]->(nested:MyModel) | nested {. *} | ||
] | ||
} | ||
""") | ||
Optional<MyModel> getByUuidCustomQuery(String uuid); | ||
|
||
@Query(""" | ||
MATCH (root:MyModel {uuid: $uuid}) | ||
RETURN root { | ||
.*, MyModel_REL_TO_MY_NESTED_MODEL_MyModel_true: [ | ||
(root)-[:REL_TO_MY_NESTED_MODEL]->(nested:MyModel) | nested {. *} | ||
] | ||
} | ||
""") | ||
Optional<MyModel> getByUuidCustomQueryV2(String uuid); | ||
} |