Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » HasManyDataObjectManager breaks site

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2
Go to End
Author Topic: 1645 Views
  • MagicUK
    Avatar
    Community Member
    60 Posts

    HasManyDataObjectManager breaks site Link to this post

    Hi. Was hopeing for a bit of help. Can't understand this one.

    on page Speakers.php is have the code:

    class Speakers extends DataObject {

       static $db = array(
    'FirstName' => 'Text',
    'LastName' => 'Text',
    'Position' => 'Text',
    'Company' => 'Text',

    );
    public static $has_one = array(
          'Speaker' => 'SpeakersPage',
          'SpeakerImage' => 'Image',      
          
       );

    function getCMSFields_forPopup() {
    $fields = new FieldSet();

    $fields->push( new TextField( 'FirstName', 'First Name' ) );
    $fields->push( new TextField( 'LastName' ) );
    $fields->push( new TextField( 'Position' ) );
    $fields->push( new TextField( 'Company' ) );
    $fields->push( new ImageField('SpeakerImage') );

    return $fields;
    }

    ...

    and on SpeakersPage.php

    <?php
    class SpeakersPage extends SiteTree {

       public static $db = array(
       'RightContent' => 'HTMLText',
       
       );

       public static $has_one = array(

       );
       
       public static $has_many = array(
          'MySpeakers' => 'Speakers',
       );
       
       
        function getCMSFields() {
    $fields = parent::getCMSFields();

    $tablefield = new HasManyDataObjectManager(
    $this,
    'MySpeakers',
    'Speakers',
    array(
    'FirstName' => 'First Name',
    'LastName' => 'Family Name',
    'Position' => 'Position',
    'Company' => 'Company',
    'SpeakerImage' => 'Speaker Image',
    ),
    'getCMSFields_forPopup'
    );

    $tablefield->setParentClass('Speakers');
    $fields->addFieldToTab( 'Root.Content.Speakers', $tablefield );

    This doesn't work? If I use the class 'DataObjectManager' it is fine. Of course, I would like to be able to use the HasManyDataObjectManager as each Speaker page will display different speakers. Can you point me as to where I'm going wrong here?

    Thanks

  • UncleCheese
    Avatar
    4085 Posts

    Re: HasManyDataObjectManager breaks site Link to this post

    What does "doesn't work" mean?

  • MagicUK
    Avatar
    Community Member
    60 Posts

    Re: HasManyDataObjectManager breaks site Link to this post

    Sorry for being vague. I get a white blank page when visiting the webpage. With just the titles of pages on the site.

  • MagicUK
    Avatar
    Community Member
    60 Posts

    Re: HasManyDataObjectManager breaks site Link to this post

    In dev mode I get the following error when visiting the CMS:

    [User Error] Couldn't run query: SELECT "Speakers"."ClassName", "Speakers"."Created", "Speakers"."LastEdited", "Speakers"."FirstName", "Speakers"."LastName", "Speakers"."Position", "Speakers"."Company", "Speakers"."SortOrder", "Speakers"."SpeakerID", "Speakers"."SpeakerImageID", "Speakers"."ID", CASE WHEN "Speakers"."ClassName" IS NOT NULL THEN "Speakers"."ClassName" ELSE 'Speakers' END AS "RecordClassName", SpeakerImage FROM "Speakers" ORDER BY "SortOrder" ASC LIMIT 0, 10 Unknown column 'SpeakerImage' in 'field list'
    GET /event/admin/

    Line 525 in /var/www/vhosts/xxx/httpdocs/event/sapphire/core/model/MySQLDatabase.php

  • MagicUK
    Avatar
    Community Member
    60 Posts

    Re: HasManyDataObjectManager breaks site Link to this post

    At a loss of why the HasManyDataObjectManager is telling me there is an unknown column when it works with DataObjectManager and HasManyComplexTableField?

  • MagicUK
    Avatar
    Community Member
    60 Posts

    Re: HasManyDataObjectManager breaks site Link to this post

    Can someone please help me on this? I'm stressed out my box trying to get it to work.

  • MagicUK
    Avatar
    Community Member
    60 Posts

    Re: HasManyDataObjectManager breaks site Link to this post

    I'm still struggling with this. Have no idea. At my whits end. If someone could maybe provide some pointers I would appreciate it! Am I missing something stupid?

  • UncleCheese
    Avatar
    4085 Posts

    Re: HasManyDataObjectManager breaks site Link to this post

    Well you could always just remove SpeakerImage from your field list if you really want to get it fixed fast. It's unusual to put an image right in your field list like that.. most of the time you want to put in some sort of thumbnail function or something, so it can be sized appropriately for the table.

    public function getSpeakerThumbnail() {
    if($this->SpeakerImage()) {
    return $this->SpeakerImage()->CroppedImage(50,50);
    }
    return false;
    }

    and in your fields list:

    'SpeakerThumbnail' => 'Speaker Image'

    Also, I'm wondering if HasManyDOM is really what you want? It's very rarely used. Most of the time you want a DOM or a ManyManyDOM. There aren't too many models that I have seen where HasManyDOM is appropriate.

    --------------------
    SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com

    1645 Views
Page: 1 2
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.