Skip to content

Create the associated model of fixture if it doesn't exist.#47

Open
jasonku wants to merge 1 commit intodomasx2:masterfrom
jasonku:support_association_creates
Open

Create the associated model of fixture if it doesn't exist.#47
jasonku wants to merge 1 commit intodomasx2:masterfrom
jasonku:support_association_creates

Conversation

@jasonku
Copy link
Copy Markdown

@jasonku jasonku commented Jan 26, 2016

  • Sequelize supports creating of associated models in one step. See:
    docs.sequelizejs.com/en/latest/docs/associations/#creating-with-associations
  • If the associated model of a fixture doesn't exist in the database
    yet, pass along the data of the associated model so that it's included
    in Model.build and ends up getting created.

* Sequelize supports creating of associated models in one step. See:
  docs.sequelizejs.com/en/latest/docs/associations/#creating-with-associations
* If the associated model of a fixture doesn't exist in the database
  yet, pass along the data of the associated model so that it's included
  in `Model.build` and ends up getting created.
@domasx2
Copy link
Copy Markdown
Owner

domasx2 commented Mar 23, 2016

I kinda feel in a curmudgeony-coservative-asshat sort of way that associated models are better created explicitly

@jasonku
Copy link
Copy Markdown
Author

jasonku commented Mar 24, 2016

This PR doesn't take away the ability to explicitly create associated models in separate calls. It just adds the ability to create the associated model in one call.

@skinofstars
Copy link
Copy Markdown

If this provides the option to create associations on the fly using nesting, and it causes no backwards incompatibility, then this would be an amazing feature!

@jasonku
Copy link
Copy Markdown
Author

jasonku commented Dec 18, 2017

@domasx2 Any plans to either merge or close this? This change is backwards compatible.

Comment thread lib/loader.js
result[assoc.identifier] = obj[assoc.target.primaryKeyField || 'id'];
if (obj) {
result[assoc.identifier] = obj[assoc.target.primaryKeyField || 'id'];
} else {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a check here to ensure that on-the-fly association creation is what is intended? Actually this area of code currently has bad error reporting.

I suggest we add a check if the option was specified, if not, it should error and say association not found , such:

throw new Error('No associated model found for: \n\t' + JSON.stringify(options) + '\nwhile processing fixture: \n\t' + JSON.stringify(data));

I'm not positive about the logic to check if your include option was specified, could you add it along with this fallback error case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants