i have a table-NOTICES,
the entries in this table are populated by
the user of the app. i want to limit the no of rows to say 50. When the
51st entry is made to the table, i want the oldest one to get
automatically deleted and make space for the new entry.
please help me with this!~!!!
Hello!
It can be implemented with business logic feature. Create beforeCreate handler for the target table and inside it implement logic which would check out if the quantity on objects is in allowed range. If not - remove redundant row.
Here is a link to BL docs: https://backendless.com/documentation/business-logic/java/bl_data_service_handler.htm
best regards,
Alex
Sir, I have already gone through this page. I know the logic but the
methods to be used for this are still not clear. So, can you please help
me with the code ??
Here you have a code sample for your handler, assuming that you table is called “MyTable”:
int objectsInTable = Backendless.Data.of( MyTable.class ).find().getTotalObjects();
if( objectsInTable >= 50 )
{
MyTable firstObject = Backendless.Data.of( MyTable.class ).findFirst();
Backendless.Data.of( MyTable.class ).remove( firstObject );
}
Thank You so much…i ll try this code and i hope this works…and let you know if i encounter any problem.