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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

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

Problem with subclasses and fields


Go to End


838 Views

Avatar
Rodskagg

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.