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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

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

Problem with subclasses and fields

Go to End



Community Member, 26 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.