Hi zim
I guess the problem exists because a Page is usually stored in two different tables, one for Live and one for Draft mode. And yes, raw DB querys usually target only a single table.
If you're feeling uncomfortable with raw SQL queries, you could also get a set of your pages, iterate over it and set the IsMainStory flag.
Something like this:
function onAfterWrite() {
// call parent first
parent::onAfterWrite();
if($this->IsMainStory == false)
return;
$set = DataObject::get($this->ClassName);
if(!$set)
return;
foreach($set as $item){
if($item->ID != $this->ID){
$item->IsMainStory = false;
$item->write();
}
}
}
If that doesn't work for you, please post the code of your class at http://pastie.org/ and provide us a link to it so we can have a look.
Update Oh.. important. You should probably use onAfterWrite insted of onBeforeWrite, since only then you can be sure that the flag and ID has been written to DB! I changed the code above accordingly