Jump to:

3430 Posts in 1057 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Problem with subclasses and fields

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

Page: 1
Go to End
Author Topic: 264 Views
  • Rodskagg
    Avatar
    Community Member
    8 Posts

    Problem with subclasses and fields Link to this post

    I have a data object called ImageLink which extends DataObject and a data object called Promo which in turn extends ImageLink. In my page I have two has_many fields - one for ImageLinks and one for Promos.

    static $has_many = array(
          "ImageLinks" => "ImageLink",
          "Promos" => "Promo"
       );

    Since Promo inherits from ImageLinks, when I get/loop the ImageLinks items they also include the Promo items stored in the Promos field. Is this the intended behaviour? I'm not interested in getting any subclasses. When looping the ImageLinks i only wish to get the ImageLinks! I understand where the problem comes from, since all ImageLinks and Promos are stored in the same table in the database.

    At the moment, I have to filter the ImageLinks array on "ClassName" = "ImageLinks", but it would be better if this worked out of the box.

    264 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.