phpormsilverstripemodeladmin

Blank Screen When DataObject Only Has ManyMany Relationship


The following code makes a ModelAdmin for MyDataObject. When adding a MyDataObject the edit form is empty because many_many relationships can only be seen after saving.

class TestAdmin extends ModelAdmin {
    static $managed_models = array('MyDataObject');
    static $url_segment = 'testadmin';
    static $menu_title = 'TestAdmin';
}

class MyDataObject extends DataObject {
    private static $many_many= array('MyOtherDataObjects' => 'MyOtherDataObject');
}

class MyOtherDataObject extends DataObject {
    private static $db = array('Name' => 'Varchar(255)');
    private static $belongs_many_many = array('MyDataObjects' => 'MyDataObject');
}

Is there any method of having the many_many relationships exist right away?

If not is there a way of creating the object and then removing it if no relationships are saved?


Solution

  • If I understood correctly, your Package can have many filters and one Filter can be used by different Package. Then you have many-many relation between Package and Filter. The list of the products is dynamic, you can calculate it every time.

    Your users should refer to the Package somehow, so it should have a property Name and you have at least one input box to add new Package (not the blank screen as you have now).

    Update

    The behaviour you have described is correct and expected.The ManyManyList state is synchronised with database, so you cannot have items stored just in memory until you decide to store the list in the DB out of the box.

    You could substitute the Add New button with your own implementation to automatically create new object, save it in the DB and redirect to edit screen.