Code Monkey home page Code Monkey logo

Comments (3)

smalluban avatar smalluban commented on May 28, 2024

If the nested model is external (has an id, or defined storage), then the root model keeps the reference, which in moment of the definition can't be known (nested models are just defined there, or used, not fetched). The default value for that relation must be null. The definition of the model defines a structure, and it is not supposed to fetch anything.

What you can do, is when your form component connects (the best place would be an observe method), set up the relation for the draft (set the default) - then is it possible to fetch the nested model, and it's the right place to do so.

{
  draft: {
    ...store(Model, { draft: true }),
    observe(host, model, lastModel) {
      // only fires for the first initial get, or when model id changes (clear draft, or submit)
      if (!lastModel || model.id !== lastModel.id) {
        store.set(model, { nestedModel: host.myExternalNestedModel })
      }
    },
  },
}

The other option is to have that default in the set() method of the model storage if it is not overwritten by the user. In the UI you can set a default for the select element if the nested model is not set.

from hybrids.

Qsppl avatar Qsppl commented on May 28, 2024

Thanks, this solved the problem.

from hybrids.

smalluban avatar smalluban commented on May 28, 2024

By the way, the store.ref() is only useful for self reference or for avoiding ES module cycle imports. Otherwise it does not do anything.

from hybrids.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.