Closed beebase closed 7 years ago
Hi,
You can customize the convention for private keys. For example:
Model.conventionForPrivate = function(key){ return key.startsWith("private_") }
In the next version of ObjectModel, you will be able to set this convention specifically for one model. Currently it applies on all models.
[edit: ah thanks, I just read your comment above.]
I couldn't find an example in the docs but I guess this is the solution
Model.conventionForPrivate = (key) => {
return key[0] === '#' // only props prefixed with '#' are now handled as private
}
If you don't want private at all, you can also return false
I just upgraded from 2.6.2 to 3.1 and I'm getting private prop errors again
22:67 Uncaught TypeError: cannot modify private _from
In my code i am doing this:
import { Model } from 'objectmodel'
Model.conventionForPrivate = (key) => { return key[0] === '#' }
Are there any breaking changes perhaps?
ah ok.
Model.conventionForPrivate and Model.conventionForConstant have been moved to Model.prototype so that you can change these conventions specifically by model
yes, just change Model.conventionForPrivate
to Model.prototype.conventionForPrivate
I think a small example in the docs to make this explicit could be helpful. I spent a bit more time that I would have liked to find this hint...
I have a naming collision. My database (ArangoDb) only accepts _key as primary key. When I create a record offline I have to add {_key : uuid} in order to sync with the db when coming online again. if _key is missing in the record, the db will create it's own _key.
The problem is that ObjectModel sees _key as private and strips it when the record is sent to the db server. How can I solve this?