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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

HasManyDataObjectManager breaks site


Go to End
Reply


15 Posts   1763 Views

Avatar
MagicUK

Community Member, 60 Posts

22 July 2011 at 6:38am

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

Avatar
UncleCheese

Forum Moderator, 4096 Posts

22 July 2011 at 7:10am

What does "doesn't work" mean?

Avatar
MagicUK

Community Member, 60 Posts

22 July 2011 at 7:14am

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

Avatar
MagicUK

Community Member, 60 Posts

22 July 2011 at 7:18am

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

Avatar
MagicUK

Community Member, 60 Posts

22 July 2011 at 8:39am

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

Avatar
MagicUK

Community Member, 60 Posts

22 July 2011 at 8:45pm

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

Avatar
MagicUK

Community Member, 60 Posts

25 July 2011 at 9:42pm

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?

Avatar
UncleCheese

Forum Moderator, 4096 Posts

26 July 2011 at 1:05am

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

Go to Top