Jump to:

23007 Posts in 11866 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » Gridfield with relationEditor has_one Dataobject

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 988 Views
  • Matulko
    Avatar
    Community Member
    9 Posts

    Gridfield with relationEditor has_one Dataobject Link to this post

    hello
    I got few guestions about gridfield and creating new dataobject there

    I want create photogallery for article pages so I got this code

    class ArticlePhoto extends DataObject
    {
       public static $singular_name = 'Obrázok k článku';
       
       public static $db = array (
          'Title' => 'text'
       );
       
       public static $has_one = array (
          'Image' => 'Image',
          'Page' => 'Page',
          );
    }

    class Article extends Page
    {

       public static $has_many = array(
          'ArticlePhotos' => 'ArticlePhoto'
       );
       
       public function getCMSFields()
       {
          $f = parent::getCMSFields();
          
          $dl = DataList::create('ArticlePhoto')
             ->where('PageID ='.$this->ID);
          
          $config = new GridFieldConfig_RelationEditor();
                
          $gridField = new GridField('ArticlePhotos','ArticlePhotoGallert', $dl,$config);
                
          $f -> addFieldToTab('Root.PhotoGallery', $gridField);
          return $f;
       }
    }

    I want use this DataObject for more page subclasses so for that is is in has_one Page class

    it looks like really simple code but my probles is how to set automatically dataobject has_one page

    when I create new dataobject this is not automatically set and I am redirected to page with ID = 1
    when I delete filter '->where('PageID ='.$this->ID);' everything works fine but I still have to set this relation

    I want just create DataObject and then upload Image without set this relation
    any suggestions???

  • elgordo
    Avatar
    Community Member
    69 Posts

    Re: Gridfield with relationEditor has_one Dataobject Link to this post

    Noticed a typo in your code, ArticlePhotoGallert - should this be ArticlePhotoGallery?

  • elgordo
    Avatar
    Community Member
    69 Posts

    Re: Gridfield with relationEditor has_one Dataobject Link to this post

    Noticed a typo in your code, ArticlePhotoGallert - should this be ArticlePhotoGallery?

  • SamTheJarvis
    Avatar
    Community Member
    24 Posts

    Re: Gridfield with relationEditor has_one Dataobject Link to this post

    This is a problem I have too. There doesn't seem to be any solution for adding/editing/deleting objects that are attached through a has_one.

    Sorry I can't help, I'm looking into a way to do this.

  • Matulko
    Avatar
    Community Member
    9 Posts

    Re: Gridfield with relationEditor has_one Dataobject Link to this post

    thanks for help
    i started using multiple upload field for this

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