Addition to documentation : YAML for bidirectional relationship
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
play framework |
Fix Committed
|
Undecided
|
Unassigned |
Bug Description
This is created to tack the below mailing list conversation, as suggested by Guillame.
http://
The relevant part: (you may use the below classes from the attached file)
-------------------
@Dirk.
I can't thank enough, as I have been struggling with it. thanks for
the detailed example. For further reference, I keep the example below.
2 notes
1. Used @Table(name = "`user`") annotation as User is a reserved word
in PostgreSql
2. I had to reverse the many to many mapping as I considered
Neighborhood as the owning entity
~~~~~~~~~ Code ~~~~~~~~~~~~
Neighborhood.java
-----------------
package models;
import java.util.List;
import javax.persisten
import play.db.jpa.Model;
@Entity
public class Neighborhood extends Model {
public String name;
@ManyToOne
public City city;//
public String tags;
@ManyToMany //owning side
public List<User> users;
}
User.java
------------
package models;
import java.util.*;
import javax.persisten
import play.db.jpa.Model;
@Entity
@Table(name = "`user`")
public class User extends Model {
public String name;
public String email;
public String lang;
public Date created;
@ManyToMany
public List<Neighborhood> neighborhoods;
}
City.java
---------
package models;
import java.util.*;
import javax.persisten
import play.db.jpa.Model;
@Entity
public class City extends Model {
public String name;
public String state;
@OneToMany(
directional one-to-many, inverse side
public List<Neighborhood> neighborhoods;
}
YAML
----
City(capitalfed
name: Capital Federal
state: Buenos Aires
User(john):
name: "John Smith"
email: <email address hidden>
lang: es
created: 2007-01-01
#neighborhoods: [coghlan, villalugano]
User(frank):
name: "Frank Franken"
email: <email address hidden>
lang: en
created: 2007-08-05
#neighborhoods: [villalugano]
Neighborhood(
name: Villa Lugano
city: capitalfederal
tags: "shopping, cafes"
users: [john, frank]
Neighborhood(
name: Coghlan
city: capitalfederal
tags: "cafes, bars"
users: [john]
I've created a documentation page including the example above: bazaar. launchpad. net/~australian developer/ play/1. 1-dev/revision/ 981
http://