balderdashy / balderdashy/sails

When using sails-disk any attribute with `unique:true` must also have `required:true`

Open
#4,559 19 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

helpful info or workaround orm
Dominant language
JavaScript
Stars
22.8k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

Sails version: 1.1.0
Node version: 8.14.0
NPM version: 6.4.1
DB adapter name: sails-disk
DB adapter version: N/A
Operating system: Windows 10


I have one-to-one relationship. A task must have a message. Even though I set required to true in the Task.message relationship, I keep getting error "In attribute message of model task: When using sails-disk, any attribute with unique: true must also have required: true". My code:

/api/models/Task.js

message: {
      model: 'message',
      required: true,
      unique: true
},

/api/models/Message.js

task: {
      collection: 'task',
      via: 'message'
},

When using sails-disk any attribute with unique:true must also have required:true.

I asked on gitter and they said:

Did you try with a real database? May be there is a bug in sails-disk and throwing a wrong message. May be sails-disk adapter is looking at the relationship as 1-to-m. I suggest execute your code with a real database and then post your findings

I tried with sails-mysql and no issue. I reported this in gitter to see if they could help more, they said not to use sails-disk.

I think this is a bug, and I don't want to just ignore it if I found it. So reporting it here.

Gitter comments:

sails-disk is very simple implementation based on json file. It is not a DBMS so do not expect much from it. It is made available for quick prototyping. Do not use

It would be nice if we could fix sails-disk so it didn't get a bad rep like this. They tell me simply to not use it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the relationship setup from /api/models/Task.js and /api/models/Message.js using sails-disk, then compare the result with sails-mysql. Start by tracing how sails-disk interprets the required, unique, model, and collection attributes. Done means the valid one-to-one relationship no longer produces the misleading validation error under sails-disk.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.