Devone
Devone

Reputation: 175

Does silverstripe have recursive data relationships?

Does silverstripe have recursive data relationships? I tried to implement it and it gives no errors but the page is blank on modeladmin.

Example has_one recursive relation on Product to itself:

class Product extends DataObject {

    private static $db = array(
        'Name' => 'Varchar',
        'ProductCode' => 'Varchar',
        'Price' => 'Currency'
    );

    private static $has_one = array(
        'Product' => 'Product'
    );
}

Upvotes: 1

Views: 118

Answers (2)

Dan Hensby
Dan Hensby

Reputation: 1143

Yes, this is possible.

There can be problems when doing this with Many_Many relationships, though.

Upvotes: 2

Barry
Barry

Reputation: 3318

My answer would be "no" for this done in this way. Where I've need this in the past I've created the "has one" as an "int" in the db array...

class Product extends DataObject {

    private static $db = array(
        'Name' => 'Varchar',
        'MyProductID' => 'Int',
    );

}

this means I've had to add casting for the summary field, custom scaffolding for the search fields and in the getCMSFields to replaceField the int field for a DropdownField to select a product.

Upvotes: 0

Related Questions