Skip to content

Many-to-many relationships

Many-to-many relationships are implemented in Para with Linker objects. This object contains information about a link between two objects. This is simply the id and type of both objects. Linker objects are just regular Para objects - they can be persisted, indexed and cached.

+--------+
| tag1 |
+---+----+
|
+---+------------+
|post:10:tag:tag1| Linker
+---+------------+
|
+---+------+
| Post1 |
| id:10 |
+----------+
object1.link(object2.getType(), object2.getId());
object1.unlink(object2.getType(), object2.getId());
// delete all links to/from object1
object1.unlinkAll();

To check if two objects are linked use:

object1.isLinked(object2.getType(), object2.getId())

Also you can count the number of links by calling:

object1.countLinks(object2.getType())

Finally, to read all objects that are linked to object1, use:

object1.getLinkedObjects(object2.getType(), Pager... pager);