繁体   English   中英

Play Framework 1.2.x中的ManyToMany测试治具(Yaml)

[英]ManyToMany Test Fixtures (Yaml) in Play Framework 1.2.x

我正在使用Play! 1.2.4 + Morhpia / MongoDB。

我的模型是沙龙和造型师,它们之间存在许多关系。 但是,我无法正确定义测试数据来表示这种关系。

这就是我所做的

Salon(salon1):
  name: salon1
  city: singapore
  country: singapore

Stylist(stylist1):
  firstName: stylist1
  lastName: stylist1
  title: Stylist 1
  price: $100
  salons: [salon1]

有了这些数据,设计师就包含了沙龙的参考,反之亦然。

如何实现双向引用?

谢谢,斯里


这是模型类..

@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;
  // ..
}

两种方式引用是什么意思?

如果您想通过代码从Salon实体访问Stylists,那么您将需要具有以下内容:

public class Salon extends Model {

    @ManyToMany
    @JoinTable(name = "salon_stylist", ...)
    public List<Stylist> stylists;

    ...
}

您的造型师实体看起来可能像这样:

public class Stylist extends Model {

    @ManyToMany
    @JoinTable(name = "salon_stylist", ...)
    public List<Salon> salons;

    ...
}        

然后,您的yml可能如下所示:

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

只是说stylist1属于salon1和salon2在yml中就足够了(即,您不必在两个沙龙yml条目中声明相同的名称)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM