Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Adding different DataObjects to same ComplexTableField

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

Page: 1
Go to End
Author Topic: 1275 Views
  • J
    Avatar
    Community Member
    3 Posts

    Adding different DataObjects to same ComplexTableField Link to this post

    Hi,

    I have a portfolio page that I want to add several different pieces of media to it. Media at this point is either an image or a swf file but later could be more than that.
    A media attachment always has a title, the piece of media (file) and a thumbnail.
    There are also some differences between the pieces of media. For example for a swf file I also need to store a width and height variable to use later in the html to display it.

    I would like to know how to add these two different media attachments, order them (so a page could display say image, swf, image) and have different fields for different media types?

    At the moment I have a ComplexTableField in the portfolio page for adding media attachments. So when I go to add a portfolio page to my site I get a complex table field with an "Add Media Attachment" down the bottom. When you add a media attachment it pops up to add the title, thumbnail and file. Unfortunately I can't figure out how to add these extra fields just for attaching swf files. Does anyone have a good solution?

    J

  • MarcusDalgren
    Avatar
    Community Member
    288 Posts

    Re: Adding different DataObjects to same ComplexTableField Link to this post

    As far as I know this is not supported. If you want to manage two different data objects you'll have to add two complextablefields/dataobject managers. However when fetching them for display you can mix them.

    Let's say your porfolio has something like this

    ...
    public static $has_many = array(
    "ImageAttachments" => "ImageAttachment",
    "MovieAttachments" => "MovieAttachment"
    );
    ...

    Setup two complextablefields or DOM:s in the cms to manage the content and then write a fetch method, for example:
    public function getAttachments() {
    $images = $this->ImageAttachments();
    $movies = $this->MovieAttachments();
    $images->merge($movies);
    $images->sort("Title");
    return $images;
    }

    This way you'll get a DataObjectSet that contains both the images and the movies and they'll be ordered by title if that's what you want.

    1275 Views
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.