Play Framework 1.2.x中的ManyToMany测试治具(Yaml) [英] ManyToMany Test Fixtures (Yaml) in Play Framework 1.2.x

查看:99
本文介绍了Play Framework 1.2.x中的ManyToMany测试治具(Yaml)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

这就是我所做的

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.

如何实现双向引用?

谢谢, 斯里

这是模型类..

@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?

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

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:

public class Salon extends Model {

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

    ...
}

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

And your Stylist entity can look like this:

public class Stylist extends Model {

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

    ...
}        

然后您的yml如下所示:

Then your yml can 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

只需说stylist1属于salon1和salon2在yml中就足够了(即您不必在两个沙龙yml条目中声明相同).

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).

这篇关于Play Framework 1.2.x中的ManyToMany测试治具(Yaml)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆