Louis Adekoya
Posts: 0
Joined: Sun Nov 17, 2013 10:51 pm

How do I relate records in a collection to each other?

I have an appery.io database with three collections - Users, Group, GroupMember. A GroupMember record points to a group and to a user. Now I want to add a fourth collection 'Message' to hold records of group members' messages to each other.

So far I have simply added two pointers in Message to the GroupMember collection, one called Sender and the other called Receiver.

First of all, is this okay? Secondly how can I constrain the relationship so that a) only members in the same group (in GroupMember) can message each other and b) Only n number of messages can be sent by any one sender to another?

Can I add one or both of these constraints at db level or must I use JS validation in the app?

Egor Kotov6832188
Posts: 0
Joined: Wed Nov 19, 2014 5:15 pm

How do I relate records in a collection to each other?

Hello Louis,
First of all, is this okay?

Yes, pointer the best way to link collection's entities by value

how can I constrain the relationship

Every time you want app to make action for certain entity which has relation:
if it is simple read or query service - include pointer id in where parameter

if it's write/create/update - add shop pointer id to _id parameter
details (http://devcenter.appery.io/documentat...)

Louis Adekoya
Posts: 0
Joined: Sun Nov 17, 2013 10:51 pm

How do I relate records in a collection to each other?

Thanks Egor, I know how to do CRUD from the app, or at least I used to (I have just returned after a year-long hiatus). What I am asking is whether I can add some validation at the database level, e.g. through ACL to ensure only group members can message each other; or add some cardinality rules to restrict the number of messages they can send.

If not is there a tutorial on using JS in the appery editor to do similar validation? I can't immediately locate one.

Egor Kotov6832188
Posts: 0
Joined: Wed Nov 19, 2014 5:15 pm

How do I relate records in a collection to each other?

Hello Louis,
can add some validation at the database level
your app decides what to show member and what to hide, all request depends on your implementation.
You can use ACL to limit one group to write something for other group.

to restrict the number of messages they can send.
this feature should be implemented also based on logic and extra collection

Return to “Issues”