Function FirstOrCreate
check and create methods on multi connections
typescript
await FedacoTestUser.createQuery().create({
id: 1,
email: 'linbolen@gradii.com'
});
await FedacoTestUser.useConnection('second_connection').find(
FedacoTestUser.useConnection('second_connection').insert({
id: 2,
email: 'tony.stark@gradii.com'
})
);
let user1 = await FedacoTestUser.useConnection('second_connection').findOrNew(
1
);
let user2 = await FedacoTestUser.useConnection('second_connection').findOrNew(
2
);
Reference Looks Like Value user2._existsexactly match trueuser1.getConnectionName()exactly match 'second_connection'user2.getConnectionName()exactly match 'second_connection'
typescript
user2 = await FedacoTestUser.useConnection('second_connection').firstOrNew({
email: 'tony.stark@gradii.com'
});
Reference Looks Like Value user2._existsexactly match trueuser1.getConnectionName()exactly match 'second_connection'user2.getConnectionName()exactly match 'second_connection'await FedacoTestUser.useConnection('second_connection').count()match 1
typescript
user2 = await FedacoTestUser.useConnection('second_connection').firstOrCreate({
email: 'tony.stark@gradii.com'
});
Reference Looks Like Value user2.getConnectionName()exactly match 'second_connection'await FedacoTestUser.useConnection('second_connection').count()match 2
see also prerequisites
first or create
typescript
const user1 = await FedacoTestUser.createQuery().firstOrCreate({
email: 'linbolen@gradii.com'
});
Reference Looks Like Value user1.nameexactly match Undefined();
Reference Looks Like Value user2.idmatch user1.iduser2.emailexactly match 'linbolen@gradii.com'user2.nameexactly match null
Reference Looks Like Value expect(user1.id).notmatch user3.iduser3.emailexactly match 'xsilen@gradii.com'user3.nameexactly match 'Abigail Otwell'
see also prerequisites