1
如果我有這樣的代碼中的雙向test_data.yml
@Entity
public class Category extends Model {
public String title;
public Category() {}
public Category(String title) {
this.title = title;
}
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name="parent")
public List<Category> children = new LinkedList<Category>();
@ManyToOne
@JoinColumn(name="parent", insertable=false, updatable=false)
public Category parent;
public void addChild(Category child) {
Category root = this;
child.parent = root;
root.children.add(child);
root.save();
}
}
,我想在我的test_data.yml創建測試數據文件我怎麼可以鍵入嗎?我的意思是,這是雙向..
例如,如果我會做這樣的:
Category(root1):
title: root
children: [child1, child2]
Category(child1):
title: child1
parent: root1
Category(child2):
title: child2
parent: root1
我會得到這個錯誤:
Cannot load fixture initial-data.yml: No previous reference found for object of type children with key child1
但如果我不鍵入此:children: [child1, child2]
然後我會有錯誤的結構,child1和child2不會引用根。
我固定:類別(child1): 標題:child1 類別(的child2): 標題:的child2 類別(目錄root1): 標題:根 小孩:[child1,的child2] – ses 2011-04-29 09:06:59