Jump to:

3372 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » SS3 confused with getManyManyComponents()

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

Page: 1
Go to End
Author Topic: 156 Views
  • Stephan
    Avatar
    Community Member
    55 Posts

    SS3 confused with getManyManyComponents() Link to this post

    Hi experts,
    I can't get getManyManyComponents() working
    I have extend a page of type product with

    public static $many_many = array(
       'Images' => 'Image'   
    );

    So now I have a table called Product_Images with the comlumns ProductID and ImageID in my database.
    Within the CMS I can attach images to my ProductPage and everything is working fine.

    Now I want to access all images of a Product from a Shortcode.
    (it has to come from a shortcode and not within the template itself)
    I can get the current ProductID with Director::...... or from an argument of the shortcode.
    And now I want to retrieve my images related to this ProductID.
    But

    $ProductImages = new Product_Images;
    $images = $ProductImages->getManyManyComponents('Images', array('Product_Images.ProductID' => $intPageID));


    doesn't work.

    What am I doing wrong?

    TIA Stephan

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: SS3 confused with getManyManyComponents() Link to this post

    Hi Stephan,

    try...

    $product = //get product some how
    $images = $product->Images();
    foreach($images as $image) Debug::show($image);

  • Stephan
    Avatar
    Community Member
    55 Posts

    Re: SS3 confused with getManyManyComponents() Link to this post

    Ok, that worked.
    Many thanks

    156 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.