kripod / kripod/knex-orm

Update docs for update action

Open
#22 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
61
Forks
6
PR merge metrics
No merged PRs in 30d

Description

I think that it's not clear how to update a model if you don't have the properties fetched.

the most common use case is that you get an object with values that you want to update the model with. And the first instinct based on the docs is to do:

const data = {
  id: 1,
  companyId: 2,
  name: 'Olympia Pearson',
  birthDate: new Date('1982-08-20 00:00'),
};
const employee = new Employee(data, false); 
employee.save();

But if you want to update the model with all the properties you have to do:

const employee = new Employee({}, false); 
Object.assign(employee, data);
employee.save();

and for that reason I would add a set method:

/**
   * @param {Object} [props={}] Properties to assign to object
   * @returns {ModelBase} ModelBase
   */
  set(props = {}) {
    return Object.assign(this, props);
  }

So it can be called like this:

new Employee({}, false).set(data).save();

it would be a good thing also to explain in the docs the lifecycle of oldProps, and when they become just props, the concept is clear if you look through the code and tests, but not on a first glance.

Contributor guide

No contributing guide indexed for this repository

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

Start with the documented model-construction and save examples, then read the ModelBase behavior and existing tests around oldProps and props. Done means the update workflow and property lifecycle are clear in the docs, with the proposed set method and its chained usage covered if the API change is accepted.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
documentation
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.