I’m trying to query an object change its value to false e.g isDefault: false
after creating a new business profile. This is how the function looks like:
const addHandler = async () => {
try {
//first create the realm object
realm.write(() => {
realm.create(
'BusinessEntity',
TBusiness.generate(
business.accountingPeriodId!,
business.name!,
business.registrationNumber!,
business.vatRegistered!,
business.vatNumber!,
business.startDate!,
business.endDate!,
business.streetAddress!,
business.suburb!,
business.province!,
business.postalCode!,
business.autoGenerateCustomerCode!,
business.autoGenerateItemCode!,
business.invoiceMessage!,
business.quotationMessage!,
business.bankName!,
business.branchCode!,
business.accountNumber!,
business.accountName!,
true,
),
);
});
let newBusiness = await query.find(x => x.name === business.name);
let businessObject = realm.objects(TBusiness);
dispatch(addBusinessAction(newBusiness));
//update state, set previous to false
if (businessArray.businesses!.length > 0) {
//update any business entity that was created to "false"
businessObject.findIndex(x => {
if (x.name !== business.name) {
x.isDefault = false;
}
});
}
setBusiness({});
} catch (err) {
console.log(err);
throw err;
}
};
When the database is empty I’m able to create a business profile with no errors, but when I create a second business profile and try to change the previous profile field isDefault
to false
I get the following errors:
LOG [Error: Wrong transactional state (no active transaction, wrong type of transaction, or transaction already in progress)
Exception backtrace:
<backtrace not supported on this platform>]
ERROR Error: Wrong transactional state (no active transaction, wrong type of transaction, or transaction already in progress)
Exception backtrace:
<backtrace not supported on this platform>