Jump to:

23459 Posts in 18906 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » Abstract DataObjects

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 355 Views
  • avengex
    Avatar
    Community Member
    11 Posts

    Abstract DataObjects Link to this post

    Hey guys. I want to create an abstract DataObject but as many know, the database builder (and likely other things) don't like this.

    I think this would be a pretty useful feature to have, as without it, we have to take some weird steps around the lack of support.

    What is the lead dev consensus on this? Is it worth working on, and if so, what version would you want it in?

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: Abstract DataObjects Link to this post

    what version would you want it in?

    This would be a change for 3.2 as 3.1 is in testing nearing release so probably too late to get something like this in as I'm not sure what would break. As far as I know, you cannot have an abstract class extend a non abstract class so you'd need to look at making the whole DO chain abstract (viewable data, I think Object already is). To me it makes semantic sense for it to be abstract (you don't create a DataObject, in that case you'd use ArrayData).

  • annap
    Avatar
    Community Member
    2 Posts

    Re: Abstract DataObjects Link to this post

    Hi,

    some of my classes, that extend DataObject (e.g. Product) have methods with exact the same content.
    I want to outsource these methods in a parent class: MyDataObject.
    My Product class should extend MyDataObject instead of extending DataObject directly,
    but I'm not able to do that, I get the same Problem as described above. And I don't want MyDataObject to have a database table. Declaring MyDataObject abstract didn't help.

    Is there another way to achieve this:
    avoiding duplicate code
    ?

    Thanks,
    Anna

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: Abstract DataObjects Link to this post

    @annap, in that case you want to look at DataExtensions (which can be added to your data object without adding a table) or look at PHP Traits (http://addons.silverstripe.org/add-ons/simonwelsh/trait-loader)

  • annap
    Avatar
    Community Member
    2 Posts

    Re: Abstract DataObjects Link to this post

    Yes, that helped me. Thank you. DataExtension works for me.

    355 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.