Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions fields/field-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class FieldTypes extends FieldType {
}

convertToModelValue (array) {
if (!array && this.options.optional) {
if (!array) {
return
}

Expand All @@ -35,7 +35,7 @@ export default class FieldTypes extends FieldType {
}

convertToDocumentValue (array) {
if (!array && this.options.optional) {
if (!array) {
return
}

Expand Down
37 changes: 37 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const db = ormjs.connect({
class User extends db.Model {
static schema = {
name: String,
interests: { $type: [String], optional: true },
profile: {
vegan: { $type: Boolean, optional: true }
}
Expand Down Expand Up @@ -119,6 +120,42 @@ test('check list is sorted', async () => {
expect(isEqual(posts, sorted)).toBe(true)
})

test('Update with arangojs', async () => {
const { _collection } = await User

const user = await User.findOne({
where: { name: username }
})

await _collection.update(user, {
interests: ['fun', 'games']
})

const updatedUser = await User.findOne({
where: { name: username }
})

expect(updatedUser).toHaveProperty('interests')
})

test('Remove last arangojs update', async () => {
const { _collection } = await User

const user = await User.findOne({
where: { name: username }
})

await _collection.update(user, {
interests: null
})

const updatedUser = await User.findOne({
where: { name: username }
})

expect(updatedUser).toHaveProperty('interests')
})

test('remove item', async () => {
const userToRemove = await User.findOne({
where: { name: username }
Expand Down