Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » 2 page types sharing a field but with different class

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

Page: 1
Go to End
Author Topic: 817 Views
  • TotalNet
    Community Member
    181 Posts

    2 page types sharing a field but with different class Link to this post

    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?



  • Willr
    Forum Moderator
    5508 Posts

    Re: 2 page types sharing a field but with different class Link to this post

    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

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.