17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1239 Views |
-
Custom Relation Getters

10 October 2007 at 10:43am
I'm trying to do this:
class MyPage extends Page {
...
static $belongs_many_many = array(
'Others' => 'OtherPage'
);
...
function getRedOthers() {
return $this->Others("Colour='Red'");
}
function getBlueOthers() {
return $this->Others("Colour='Blue'");
}
}but when I use RedOthers and BlueOthers as controls in the same template, they return the same results (decided by whichever comes first in the template).
Is this a bug, or am I missing something?
-
Re: Custom Relation Getters

10 October 2007 at 1:43pm
yes, this is indeed a bug, exactly here:
http://open.silverstripe.com/browser/modules/sapphire/trunk/core/model/DataObject.php#L737we've been using some light php-based caching of relations for a while, and forgot to invalidate the cache properly in a case of SQL-filtering. as a quick hack, you can just copy this function into your MyPage.php (not OtherPage.php) and comment out the first line.
i've added a ticket for this: http://open.silverstripe.com/ticket/1490 - should be fixed in the next major release.
-
Re: Custom Relation Getters

10 October 2007 at 9:29pm
Thanks - that works now.
I did also try to create a single function that accepted arguments instead:
function getColourOthers($colour = "Red") {
return $this->Others("Colour='$colour'");
}
and whilst the discrete functions were fixed by removing the cache checking line, this approach still seems to be broken.
-
Re: Custom Relation Getters

10 October 2007 at 11:45pm
seems pretty straightforward to me, not sure what could go wrong in those two lines...
did you flush your template-cache?btw, the string passed to the relationship-getter is actually a snippet of SQL, so you have to make sure that its escaped properly:
$SQL_colour = Convert::raw2sql($colour);
| 1239 Views | ||
|
Page:
1
|
Go to Top |


