Skip to content
This repository has been archived by the owner on Mar 21, 2021. It is now read-only.

ManyToMany not always in json with ownerSide=false #352

Closed
1 task done
yelhouti opened this issue Jul 23, 2019 · 5 comments
Closed
1 task done

ManyToMany not always in json with ownerSide=false #352

yelhouti opened this issue Jul 23, 2019 · 5 comments

Comments

@yelhouti
Copy link
Contributor

Overview of the issue

The "non Owner" side of ManyToMany relationship is not always present in JDL, (making fluent methods in the generator break)

entity A
entity B

//works:
relationship ManyToMany {
    A{b) to B{a}
}

//works:
relationship ManyToMany {
    A to B
}

//DOES NOT work:
relationship ManyToMany {
    A{b) to B
}

If this is a "feature" not a bug, how can the generator know that Set<A> will not be present in B.java to avoid calling b.getAS().add(this); in A.java

If we want to keep this behavior (not having Set<A> in B) the logique in my opinion should be in the generator not in the .json.

Or maybe this case will juste disappear when the generators code starts using the .jdl as it's input, and if we want it back we will need to code the right way in the generator.

Motivation for or Use Case

This clearly can be avoided by changing the JDL, but it should be a known issue to avoid wasting other peoples time.

This is a bug because, the generated code does not compile

JHipster Version(s)

6.1.2 (don't think it's a regression) it's a side effect of adding fluent methods for add...

  • Checking this box is mandatory (this is just to show you read everything)
@MathieuAA
Copy link
Member

I'll test this out and fix it. Thanks for reporting this issue!

@MathieuAA
Copy link
Member

I wonder if it's not an issue with the generator, that should allow unidirectional many to many...

@MathieuAA
Copy link
Member

MathieuAA commented Sep 28, 2019

The fix is quite easy:

  • in the entity parser, add a check and fill the other side
  • update tests and add a new one in the entity parser

the code to add in the entity parser, after l.350

if (!relatedRelationship.injectedFieldInTo) {
        relationship.otherEntityRelationshipName = lowerFirst(relatedRelationship.from);
        const otherSideRelationship = {
          relationshipName: camelCase(relatedRelationship.from),
          otherEntityName: camelCase(relatedRelationship.from),
          relationshipType: _.kebabCase(MANY_TO_MANY),
          otherEntityField: lowerFirst(otherSplitField.otherEntityField),
          otherEntityRelationshipName: lowerFirst(relatedRelationship.to),
          ownerSide: false
        };
        relatedRelationship.type = MANY_TO_MANY;
        entities[relatedRelationship.to].addRelationship(otherSideRelationship);
      }

@yelhouti
Copy link
Contributor Author

@MathieuAA This is what I tried to explain in the issue, sadly didn't have time to work on it, I'm in a bit of pickle these days with some projects so sorry, I can't help any further for now.

@MathieuAA
Copy link
Member

Don't worry! I'll try to get to the bottom of this :) again, thanks for reporting this one

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

No branches or pull requests

2 participants