-
Notifications
You must be signed in to change notification settings - Fork 9
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
Bug when using multiple relationships to same collection in one class #53
Comments
Hello
Your problem is that you are using the same name in the @JoinProperty annotation.
Regards,
Kaiso
…Sent from my iPhone
On 26 Jun 2020, at 15:35, sverin ***@***.***> wrote:
I found another thing that I think is a bug. In our model we would like to have a one-to-many relationship to another collection but in two different fields. But that seems to screw things up.
In the example below I have two fields on the Offer class, products and addons, referring with a OneToMany relationship to the same collection products. The products for both fields has been saved earlier and exists in the database.
@document(collection = "offers")
@typealias(value = "offer")
public class Offer {
@id
private String id;
private String name;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.NONE)
@JoinProperty(name = "products")
private List<Product> products;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.NONE)
@JoinProperty(name = "products")
private List<Product> addons;
}
@document(collection = "products")
@typealias(value = "product")
public class Product {
@id
private String id;
private String name;
}
Below is the data added. I have a ModelMapper converter that converts the string ids in products and addons to real objects before saving. And it works when I remove the relationship to addons.
{
"name": "My Offer",
"category": "CATEGORY_X",
"subcategory": "SUB_CATEGORY_Y",
"products": [
"5ef5f73d9959571a685ade51"
],
"addons": [
"5ef5f75d9959571a685ade54"
],
"rules": []
}
The result in MongoDB is a document that looks like this. It has saved the product reference from addon into the products field. And addon reference is completely missing.
{
"_id" : ObjectId("5ef5f7ba9959571a685ade56"),
"name" : "My Offer",
"category" : "CATEGORY_X",
"subcategory" : "SUB_CATEGORY_Y",
"_class" : "offer",
"products" : [
{
"_id" : ObjectId("5ef5f75d9959571a685ade54"),
"_relmongo_target" : "products"
}
]
}
Thanks for any help you could provide. It's a great library.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Thank you, I though that referred to the collection name to join with. Now it works fine. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I found another thing that I think is a bug. In our model we would like to have a one-to-many relationship to another collection but in two different fields. But that seems to screw things up.
In the example below I have two fields on the
Offer
class,products
andaddons
, referring with a OneToMany relationship to the same collectionproducts
. The products for both fields has been saved earlier and exists in the database.Below is the data added. I have a
ModelMapper
converter that converts the string ids inproducts
andaddons
to real objects before saving. And it works when I remove the relationship toaddons
.The result in MongoDB is a document that looks like this. It has saved the product reference from addon into the products field. And addon reference is completely missing.
Thanks for any help you could provide. It's a great library.
The text was updated successfully, but these errors were encountered: