Hello,
In my project are three page types planed:
Artist, Location,Concert
The Concert has_one Location and many_many Artists, rather simple.
After a /db/build/?flush=1 my database has the extra fields for the $db variables end a table named "concert_artists" with ID (pk), ConcertID and ArtistID.
When I create a new Artist and assign some concerts the data gets stored in the db. The other way round, assigning some artists and a location to the concert fails without any error :(
Code:
<?php
/* Artist.php */
class Artist extends Page
{
static $db = array (
'Instrument' => 'Varchar',
'Link' => 'Varchar'
);
static $allowed_children = "none";
static $can_be_root = false;
static $belongs_many_many = array ('Concerts' => 'Concert' );
static $has_one = array( 'Photo' => 'Image');
function getCMSFields()
{
$fields = parent::getCMSFields();
$concertsList = DataObject::get('Concert');
if (!is_null($concertsList)) // catch cms error, if no concert exits
$fields->addFieldToTab('Root.Content.Concerts', new CheckboxSetField('Concerts', '', $concertsList));
$fields->addFieldToTab('Root.Content.Main', new TextField('Name') );
$fields->addFieldToTab('Root.Content.Main', new TextField('Instrument'));
$fields->addFieldToTab('Root.Content.Main', new TextField('Link'));
return $fields;
}
}
class Artist_Controller extends Page_Controller{}
?>
<?php
/* Location.php */
class Location extends Page {
static $db = array(
'ZIP' => 'Int',
'City' => 'Text',
'Langitude' => 'Float',
'Longitude' => 'Float',
'Country' => 'Text',
);
static $belongs_many_many = array ( 'Concerts' => 'Concert');
function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Details', new TextField('ZIP'));
$fields->addFieldToTab('Root.Content.Details', new TextField('City'));
$fields->addFieldToTab('Root.Content.Details', new TextField('Country'));
$fields->addFieldToTab('Root.Content.Details', new TextField('Langitude'));
$fields->addFieldToTab('Root.Content.Details', new TextField('Longitude'));
return $fields;
}
}
class Location_Controller extends Page_Controller { }
?>
<?php
/* Concert.php */
class Concert extends Page
{
static $db = array (
'EventDate' => 'Datetime',
'Name' => 'Text',
'Description' => 'HtmlText',
);
static $many_many = array ( 'Artists' => 'Artist' );
static $has_one = array('Location' => 'Location');
static $default_parent = 'ConcertsHolder';
static $can_be_root = false;
static $allowed_children = "none";
function getCMSFields($cms)
{
$fields = parent::getCMSFields($cms);
$artistList = DataObject::get('Artist');
if (!is_null($artistList))
$fields->addFieldToTab('Root.Content.Artists', new CheckboxSetField('Artist', '', $artistList));
$locationList = DataObject::get('Location');
if (!is_null($locationList))
$fields->addFieldToTab('Root.Content.Location', new CheckboxSetField('Location', '', $locationList));
$fields->addFieldToTab('Root.Content.Main', new PopupDateTimeField('EventDate', 'Event Date'), 'Content');
return $fields;
}
}
class Concert_Controller extends Page_Controller{}
?>
Do you find some mistake? Any help would be nice!
Bye,
Wewo
Ps: I'm using SS 2.2.3 with fix for RelationComplexTable.js