I’m using Play! 1.2.4 + Morhpia / MongoDB.
My models are Salons and Stylists which share a many to many relationship. I am however unable to define the test data correctly to represent this relationship.
Here’s what I have done
Salon(salon1):
name: salon1
city: singapore
country: singapore
Stylist(stylist1):
firstName: stylist1
lastName: stylist1
title: Stylist 1
price: $100
salons: [salon1]
With this data, the stylist contains the reference to the salon but not vice-versa.
How to achieve two way referencing?
Thanks,
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;
// ..
}
What do you mean by two way referencing?
If you mean you want to be able to access Stylists from your Salon entity in code, then you will need to have something like this:
And your Stylist entity can look like this:
Then your yml can look like this:
Just saying that stylist1 belongs to salon1 and salon2 should be enough in the yml (i.e. you shouldn’t have to declare the same in the two salon yml entries).