bummzack / page-blocks

Page Blocks Module for SilverStripe
BSD 3-Clause "New" or "Revised" License
15 stars 12 forks source link

Cannot use with populate #10

Open wernerkrauss opened 8 years ago

wernerkrauss commented 8 years ago

Hi, when trying to add Blocks using populate (https://github.com/dnadesign/silverstripe-populate) it crashes:

  • Creating faq (ContentSectionBlock) ERROR [User Error]: Uncaught SS_DatabaseException: Couldn't run query:

SELECT MAX("SortOrder") FROM "Block" WHERE "ParentID" =

Somehow the Parent relation is added after creating it first?

Changing Block::onBeforeWrite to

if (!$this->exists() && !$this->SortOrder && $this->ParentID) {

fixes this problem locally.

bummzack commented 8 years ago

Interesting. So when you populate the blocks, you don't set their parent-id? How do you establish the relation to the pages?

The problem with your fix is, that it will probably never write the sortorder, since once the Block is written the $this->exists() check will return true.

I guess it makes more sense to reduce the check to SortOrder and ParentID then…