Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions /

Problem with subclasses and fields


Reply


288 Views

Avatar
Rodskagg

Community Member, 8 Posts

25 April 2013 at 3:25am

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.