Overload Enum in SilverStripe DataExtension

时光怂恿深爱的人放手 提交于 2019-12-24 00:35:54

问题


Is it possible to overload an Enum field using a DataExtension?

class Order extends DataObject {
    private static $db=array('Status'=>"Enum('Unpaid, Paid','Unpaid')";
}

class OrderExtension extends DataExtension {
    private static $db=array('Status'=>"Enum('Unpaid, Paid, Cancelled','Unpaid')"; //doesn't work
}

回答1:


I couldn't figure out how to get the augmentDatabase() method to work, but after speaking with a colleague he suggested using config.yml and this did the trick.

Order:
    db:
        Status: Enum('Unpaid, Paid, Cancelled','Unpaid')



回答2:


This appears not to be possible using the methods we've discussed so far. I implemented the OP's code and found the same thing, that the table of the decorated object ("Order" in this case) was not updated as expected.

I can sort of reason as to why this is not implemented via a DataExtension given that dev's may screw with some core logic that relies on specific table and column specs.

I did a little digging and found that what OP wants is possible, but with a bit of code. Looking at the following page: https://docs.silverstripe.org/en/3.3/reference/dataextension/#custom-database-generation it suggests defining an augmentDatabase() method on the custom DataExtension.

However, there don't seem to be any detailed docs on what to do next. Instead the page above advises to check out the core Versioned extension which, after grepping my entire SS project, is the only DataExtension subclass I could find that declared an augmentDatabase() method. Given that Versioned needs to deal with x3 tables for each class it decorates (SiteTree, SiteTree_Live, SiteTree_versions) then its logic is bound to be quite involved. I suspect however that for a custom implementation on a DataObject, things may be a little simpler. (Unless you're versioning DataObjects too that is!).

Good luck :-)



来源:https://stackoverflow.com/questions/37352714/overload-enum-in-silverstripe-dataextension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!