Dear Backendless,
I have a table with 2 relationships to other tables only. The definition is as follows:
table latest_post
post - Data relation (1:1) post - <no default value> - Non Null
owner - Data Relation (1:1) User - <no default value> - Non Null, Unique Value
I create records in this table from a Post Create event on the post table in Java.
The code is as follows:
public void afterCreate( RunnerContext context, Post post, ExecutionResult<Post> result ) throws Exception
{
try
{
Latest_post latest_post;
Backendless.UserService.login("1da1ac26-b7b6-4238-8453-cc5fcc5cb785", "SuperUserPassword");
latest_post = new Latest_post();
latest_post.setPost(post);
latest_post.setOwner(post.getOwner());
latest_post.setOwnerId(post.getOwnerId());
latest_post.save();
}
catch( BackendlessException exception )
{
System.out.println("Exception " + exception.getDetail());
}
}
Every time I create a new post in the post table, this trigger runs and creates a record in the latest_post table. The problem is that it completely breaks the constraints on the owner column. If a previous record exists with the same owner, then the field is nullified before the new record is created. In other words, neither the Unique Value nor the Non Null constraint are respected.
Expected behaviour: throw an exception that a record already exists.
Thanks!