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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page to DataObject Relation to DataObject using HasOneDOM and HasManyDOM


Go to End


2 Posts   898 Views

Avatar
Muaddib

Community Member, 4 Posts

8 February 2012 at 8:41am


I have Project Pages, which can have assigned one Mentor, and multpile Participants as DataObjects.
Each Mentor,Participant have multiple images.
Almost similar to posts above, just i'm using HasOneDOM and HasManyDOM

Geting error:

[User Error] Couldn't run query: SELECT "Participant"."ClassName", "Participant"."Created", "Participant"."LastEdited", "Participant"."FullName", "Participant"."PictureID", "Participant"."ID", CASE WHEN "Participant"."ClassName" IS NOT NULL THEN "Participant"."ClassName" ELSE 'Participant' END AS "RecordClassName" FROM "Participant" WHERE ("" = '7') ORDER BY Created DESC Unknown column '' in 'where clause'

It somehow doesn't make relations Participant=>something?

==========Project Page============

class Project extends Page
{
   static $has_one = array (
      'Mentor' => 'Mentor'
   );
   static $has_many = array (
      'Participants' => 'Participant'
   );

   function getCMSFields()
   {
      $fields = parent::getCMSFields();
 
      $participants = new HasManyDataObjectManager(
        $this,
        'Participants',
        'Participant',
        array(
            'FullName'=>'FullName'
        )
       );
 
      $mentor = new HasOneDataObjectManager(
        $this,
        'Mentor',
        'Mentor',
        array(
            'FullName'=>'FullName'
        )
      );

      $fields->addFieldToTab('Root.Content.Mentor', $mentor);
      $fields->addFieldToTab('Root.Content.Participants', $participants);
      return $fields;
   }
}

========== End Project Page============

==========Participant Page============

class Participant extends DataObject
{
   static $db = array (
      'FullName' => 'Text'
   );
 
   static $has_one = array(
      'Picture'=>'ImageResource'
   );
 
   static $has_many = array (
      'Projects' => 'Project',
      'Images' => 'ImageResource'
   );
   public function getCMSFields()
   {
      return new FieldSet(
         new TextField('FullName'),
         new SimpleImageField('Picture'),
         new FileDataObjectManager(
            $this,
            'Images',
            'ImageResource',
            'Attachment',
             array(
                  'Description'=>'Description'
            )
         )
      );
   }
}

==========End Participant Page============

==========Mentor Page============
Same as Participant
==========End Mentor Page============

==========ImageResourcePage Page============

class ImageResource extends DataObject {
            static $db = array(
               'Description'=>'Text'
           ;
           static $has_one = array(
               'Attachment'=>'Image',
               'Mentor'=>'Mentor',
               'Participant'=>'Participant'
           );
           public function getCMSFields() {
               return new FieldSet(
                      new TextField('Description'),
                      new FileIFrameField('Attachment')
               );
           }
    }

==========End ImageResourcePage Page============

Totaly lost in space...

Avatar
Muaddib

Community Member, 4 Posts

11 February 2012 at 9:04am

Any pointers on this still appreciated. ....