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 /

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

2 page types sharing a field but with different class

Go to End

2 Posts   1137 Views


Community Member, 181 Posts

4 March 2010 at 8:36pm

Edited: 04/03/2010 8:39pm

This looks like the right place to be asking this question.

Not an easy question to phrase so I'll explain what I am trying to do:

Class Page has an image of class Page_Image

public static $has_one=array('Image'=>'Page_Image');
$fields->addFieldToTab('Root.Content.Images', new ImageField('Image', 'Page Image'));

This works great, I have a Page_Image class that generates a couple of different sized images.

Tricky part comes when I add the ecommerce module where the Product class also has a field called "Image", this is of Product_Image class though so I was expecting that when adding an image to a Product page it would be entered into the database as such but when I look it has a class of Page_Image and the image formats called in the templates don't work.

The behaviour I was hoping for was that the same field name could be used for both page types, keeping the CMS UI clean, and that the image variations would be generated depending on which page class was being used. I guess that's not how the data/object model works.

Is there a trick I'm missing or will I have to change the field name in the Page class and use a decorator to remove that field fro mthe CMS?




Forum Moderator, 5523 Posts

13 March 2010 at 2:52pm

Easiest option is to rename your field. You might need to delete the Image columns yourself from Page since not use if SS will clean this up automatically for you. If it doesn't you might run into more issues later on