Reputation: 1683
I m new to GAE and datastore. I m trying Objectify-version 5, to access datastore. I m very confused about the way a relationship is maintained across Entity with Objectify. I cant map the idea of relational schema to Objectify framework, for basic understanding. In relational DB (like the PK/FK stuff),its much easier to get. I find it very difficult to understand the relations (1- many,many-many) with Objectify.I read the objectify doc here, still no understanding, its not clear yet.For instance,I have an objectify Entity- Manager, another Entity- Employee. I want to maintain one-2-many relation between Manager-To-Employee. Questions are -
Upvotes: 0
Views: 815
Reputation: 1674
as stated here:
How do I put a reference (like Foreign key in RDBMS) of Manager Entity in Employee Entity.
use Key<Manager>
or Ref<Manager>
. They are basically interchangable but Ref
holds a get method to fetch the entity if needed.
After reference is set, how do I get all employees working for A Manager?
If you are using your "foreign key" approach, you just need to query the datastore for Employee entities with the field "manager" equal to a ref or Key to the manager ID, like it was any other value.
How do I implement many-2-many relation for those entities
You can store reference collections like List<Key<Employee>>
or Set<Ref<Manager>
Upvotes: 2