unwanted cascade on delete

717 views
Skip to first unread message

Mark Lester

unread,
May 10, 2016, 6:29:57 PM5/10/16
to Sequelize

I thought that if I stuck
        onDelete:'SET NULL'


in my relations options objects, e.g.

{
        type
:'hasMany',
        relatedModel
:'Request',
        onDelete
:'SET NULL'
   
},

and I also put it on the child just for good measure, that Request  wouldn't get zapped.
But it does. 

Mick Hansen

unread,
May 11, 2016, 4:39:20 AM5/11/16
to Mark Lester, Sequelize
Hmm, that sounds odd, try looking at the SQL.
--
Mick Hansen
@mhansendev
mhansen.io

Mark Lester

unread,
May 11, 2016, 6:41:47 AM5/11/16
to Sequelize, mark.chr...@gmail.com
I get my crud commands printed at me, but i dont get the init stuff, the create tables. do i need to set a logging option.
but if the code looks OK, there;s no point me testing this, we know its cascading, i need to make sure pf what is actually getting passed.

Mick Hansen

unread,
May 11, 2016, 6:51:10 AM5/11/16
to Mark Lester, Sequelize
You can add console.log to sequelize.sync()
It looks OK, but you're using a middleman API it looks like?

On Wed, May 11, 2016 at 12:41 PM, Mark Lester <mark.chr...@gmail.com> wrote:
I get my crud commands printed at me, but i dont get the init stuff, the create tables. do i need to set a logging option.
but if the code looks OK, there;s no point me testing this, we know its cascading, i need to make sure pf what is actually getting passed.



Mark Lester

unread,
May 13, 2016, 10:54:52 AM5/13/16
to Sequelize
logging:console.log, cool.

So this is what I am passing to applyRelations, honest guv
[{"type":"BelongsTo","relatedModel":"Contract","onDelete":"SET NULL","orignalType":"belongsTo"},{"type":"BelongsTo","relatedModel":"Crypt","onDelete":"SET NULL","orignalType":"belongsTo"},{"type":"BelongsTo","relatedModel":"Element","onDelete":"SET NULL","orignalType":"belongsTo"},{"type":"BelongsTo","relatedModel":"Proposal","onDelete":"SET NULL","orignalType":"belongsTo"},{"type":"BelongsTo","relatedModel":"ElementRule","onDelete":"SET NULL","orignalType":"belongsTo"},{"type":"BelongsTo","relatedModel":"Parameter","onDelete":"SET NULL","orignalType":"belongsTo"},{"type":"BelongsTo","relatedModel":"Vote","onDelete":"SET NULL","orignalType":"belongsTo"},{"type":"HasMany","relatedModel":"Dialogue","orignalType":"hasMany"},{"type":"BelongsToMany","relatedModel":"Party","throughModel":"Dialogue","orignalType":"belongsToMany"}]

and this is the squeal we get, completely ignoring my 'SET NULL'. I guess I should go into the code.

CREATE TABLE IF NOT EXISTS `Requests` (`id` INTEGER auto_increment , `universalId` VARCHAR(255), `contractUniversalId` VARCHAR(255), `partyUniversalId` VARCHAR(255), `elementUniversalId` VARCHAR(255), `proposalUniversalId` VARCHAR(255), `elementRuleUniversalId` VARCHAR(255), `parameterUniversalId` VARCHAR(255), `ruleUniversalId` VARCHAR(255), `originUniversalId` VARCHAR(255), `touched` INTEGER, `model` VARCHAR(255), `action` VARCHAR(255), `data` TEXT, `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL, `deletedAt` DATETIME, `ContractId` INTEGER, `CryptId` INTEGER, `ElementId` INTEGER, `ProposalId` INTEGER, `ElementRuleId` INTEGER, `ParameterId` INTEGER, `VoteId` INTEGER, `RuleVoteId` INTEGER, `PartyId` INTEGER, UNIQUE `defaultPrimaryIndex` (`universalId`), PRIMARY KEY (`id`), FOREIGN KEY (`ContractId`) REFERENCES `Contracts` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, FOREIGN KEY (`CryptId`) REFERENCES `Crypts` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, FOREIGN KEY (`ElementId`) REFERENCES `Elements` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, FOREIGN KEY (`ProposalId`) REFERENCES `Proposals` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, FOREIGN KEY (`ElementRuleId`) REFERENCES `ElementRules` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, FOREIGN KEY (`ParameterId`) REFERENCES `Parameters` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, FOREIGN KEY (`VoteId`) REFERENCES `Votes` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, FOREIGN KEY (`RuleVoteId`) REFERENCES `RuleVotes` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, FOREIGN KEY (`PartyId`) REFERENCES `Parties` (`id`) ON DELETE SET NULL ON UPDATE CASCADE) ENGINE=InnoDB;

one issue of course is that I have had to nail myself to 3.19.3 cos epiloguie is broke. So I may be forced to make a contribution to society and get epilogue fixed.



Mark Lester

unread,
May 13, 2016, 12:06:23 PM5/13/16
to Sequelize
I kludged epilogue to work with a removeEmptyOr thing. So I am not on 3.23.1 and its stil not behaving.
I'll dig deeper.

Mark Lester

unread,
May 13, 2016, 12:06:59 PM5/13/16
to Sequelize
I am NOW on 3.23.1

Mark Lester

unread,
May 13, 2016, 1:30:38 PM5/13/16
to Sequelize
I am trying to get to the bottom. I am also setting allowNull = true in an explicitly delcared foreign key, as I thought that was an issue,  but we've got onDelete==='CASCADE' by the time we hit belongs-to.js so still looking.

Mark Lester

unread,
May 13, 2016, 3:17:18 PM5/13/16
to Sequelize
after trying to figure out what funky system you'd got for creating a function called applyRelations cos I couldnt find one, I realised that we dont actually have one of those, thats mine, and its got CASCADE hard wired on belongsTo for reasons that I have no idea about now.
Apologies as ever.


Reply all
Reply to author
Forward
0 new messages