backand - How to make foreign key required? -
for model example given in documentation, noticed can create pet
object without requiring owner
. how specify in json owner
required?
i see required switch fields tab, switch doesn't move when click on it.
[ { "name": "pets", "fields": { "name": { "type": "string" }, "owner": { "object": "users" } } }, { "name": "users", "fields": { "email": { "type": "string" }, "firstname": { "type": "string" } "pets": { "collection": "pets", "via": "owner" } } } ]
currently in json required field not supported foreign-key can workaround it. i'm backand , plan add in soon, meanwhile can either:
- add server side action in before create , before update events of "pets" object , check null value, , empty throw error. use following code:
try{ if (userinput.items == null){ throw new error('must have owner'); } } catch(err){ throw new error('must have owner'); }
- other option access mysql database directly , set column not null. after done open pets object page , click "sync database". won't show indication in backand work.
Comments
Post a Comment