Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jasonku
Copy link

@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
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
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

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
Author

jasonku commented Dec 18, 2017

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

result[assoc.identifier] = obj[assoc.target.primaryKeyField || 'id'];
if (obj) {
result[assoc.identifier] = obj[assoc.target.primaryKeyField || 'id'];
} else {
Copy link
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