ManyToMany Test (Yaml) tests in Play Framework 1.2.x

I am using Play! 1.2.4 + Morhpia / MongoDB.

My models are salons and stylists who share many relationships. However, I cannot correctly determine the test data to represent this relationship.

Here is what i did

Salon(salon1): name: salon1 city: singapore country: singapore Stylist(stylist1): firstName: stylist1 lastName: stylist1 title: Stylist 1 price: $100 salons: [salon1] 

Using this data, the stylist contains a link to the salon, but not vice versa.

How to achieve a two-way link?

Thank you Sri


Here are the model classes ..

 @Entity("salons") public class Salon extends Model { // ... @Reference @ManyToMany public List<Stylist> stylists; // ... } @Entity("stylists") public class Stylist extends Model { // .. @Reference @ManyToMany public List<Salon> salons; // .. } 
+3
source share
1 answer

What do you mean in two ways?

If you mean that you want to have access to stylists from your salon object in code, then you will need something like this:

 public class Salon extends Model { @ManyToMany @JoinTable(name = "salon_stylist", ...) public List<Stylist> stylists; ... } 

And your Stylist object might look like this:

 public class Stylist extends Model { @ManyToMany @JoinTable(name = "salon_stylist", ...) public List<Salon> salons; ... } 

Then your yml might look like this:

 Salon(salon1): name: salon1 city: singapore country: singapore Salon(salon2): name: salon2 city: tokyo country: japan Stylist(stylist1): firstName: stylist1 lastName: stylist1 title: Stylist 1 price: $100 salons: - salon1 - salon2 

Just saying that stylist1 belongs to salon1, and salon2 should be enough in yml (that is, you do not need to declare the same in two yal salon entries).

+2
source

Source: https://habr.com/ru/post/1497655/