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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

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

PageID always 0 for shild table


Go to End


3 Posts   1360 Views

Avatar
linkoovi

Community Member, 12 Posts

2 September 2010 at 12:56am

Edited: 02/09/2010 12:56am

Hi,

I have a table that will have PageID 0 (zero) it wont insert the ID of the User class <<uses>>


class SomeData extends DataObject
{
	public static $db = array(
		'Stuff' => 'Varchar(50)',
	);


	public static $has_one = array(
		"Page" => "ThaPage"
	);

}

and

class ThaPage extends SiteTree{
  public static $has_many = array(
         "SomeDataz" => "SomeData" // ??? do I need this ???
  );
  
}

class ThaPage_Controller extends ContentController{

 public function doStuff(){
  $Stuff = new SomeData();
  $Stuff->Stuff = "some stuff to tbl";
  $Stuff->write();
 }
}

The PageID ( <- SiteTree.ID ) will be 0, Do I have to make a method for SomeData that will insert the PageID ?
or im missing something?

Thanks

Avatar
swaiba

Forum Moderator, 1899 Posts

2 September 2010 at 1:15am

Hi,

Despite your friendly avatar - let's see if I can help...

I don't think you *need* it, but to use the nice silverstripe functions for accessing relationships, yes it is useful

"SomeDataz" => "SomeData" // ??? do I need this ??? 

To set the page you could do...

$Stuff = new SomeData(); 
$Stuff->Stuff = "some stuff to tbl"; 
$Stuff->setComponent ('Page', $this);
$Stuff->write(); 

or maybe...

$Stuff = new SomeData(); 
$Stuff->Stuff = "some stuff to tbl"; 
$Stuff->PageID = $this->ID; 
$Stuff->write(); 

...but I am not sure about $this being page object, you might need to use $this->data( ) to get the record to set as the component or get the ID to set directly

Avatar
linkoovi

Community Member, 12 Posts

2 September 2010 at 1:23am

Ahhh.. the $Stuff->PageID = $this->ID worked!!! why to think simple when you can do it complicated :/

Thanks mate!!!