Skip to content

Provide association options #34

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

Closed
grbsk opened this issue Jun 16, 2017 · 11 comments
Closed

Provide association options #34

grbsk opened this issue Jun 16, 2017 · 11 comments
Assignees

Comments

@grbsk
Copy link
Contributor

grbsk commented Jun 16, 2017

I'm trying to set some association options. For example, I have a HasMany where I want to disallow null in the FK and cascade on delete.

In Sequelize, I'd do something like:

childModel.belongsTo(parentModel, {
   foreignKey: {
      allowNull: false
   },
  onDelete: 'CASCADE'
});

I don't see any place in the association attributes or ForeignKey to pass in those options. See foreign keys (Their documentation on this subject is a bit messy).

I'd like to be able to do the following, using BelongsTo as an example:

export class Child extends Model<Child> {
   @BelongsTo(() => Parent, { foreignKey: { allowNull: false }, onDelete: 'CASCADE'})
    public parent: Parent;
}

I'm using Sequelize 4, but I think the issue is the same for 3.

@chanlito
Copy link
Contributor

Yeah i been reading the doc, but don't see any where to set 'CASCADE'. @RobinBuschmann can u shed some light here?

@RobinBuschmann
Copy link
Member

Unfortunately this is currently not possible with the available decorators. So at the moment you have to rely on the automatically set configuration by sequelize.

But this should be supported by sequelize-typescript. I will look into this and start implementing this feature as soon as possible.

@zuhair-naqvi
Copy link

+1

@RobinBuschmann
Copy link
Member

This feature is now part of the 0.4.0-beta release ([email protected]) @hackedbychinese thanks again for implementing.

@chanlito
Copy link
Contributor

should this be mentioned in the doc? it took me quite some time

@RobinBuschmann
Copy link
Member

@BruceHem this can already be found here: https://github.com/RobinBuschmann/sequelize-typescript#foreignkey-belongsto-hasmany-hasone-belongstomany-api

..or do you think that an example would be a good idea?

@chanlito
Copy link
Contributor

An example would be nice. And also I think we should show that this feature is available after 0.4.0-beta too.

@chanlito
Copy link
Contributor

@RobinBuschmann do we have a sequelize-typescript chat group?

@RobinBuschmann
Copy link
Member

@BruceHem You mean a chat like https://gitter.im/ ? What to you intend to achieve with a group chat? Should it be for questions, bugs, ...?

@chanlito
Copy link
Contributor

Yes!

@RobinBuschmann
Copy link
Member

@BruceHem I think it is better to keep one communication channel for now: github. A chat needs moderation and is much harder to be moderated than the github issues.

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

No branches or pull requests

4 participants