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:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Custom HasManyComplexTableField/HasManyDataObjectManager with join -- adding new items

Go to End



Community Member, 13 Posts

30 October 2009 at 9:36am

So, I'm trying to use a HasManyDataObjectManager for its sweet sorting capabilities. Since I'm not using the DOM globally, I just want to replace the HasManyComplexTableField in the model admin for a particular dataobject.

The overal picture of my situation is this--

MovieSet DataObject has_many Movies

Movie has_one MovieSet, has_one File and is sortable

The idea here is that a single file can belong to multiple movie sets and be sorted uniquely in the set.

So far so good. The problem comes once I replace the HasManyComplexTableField for the Movies of the MovieSet. In order to only show the Movies that belong to the MovieSet, I'm setting a Filter for the HasManyDataObjectManager that limits the Movie objects that appear in the grid to only ones that have a MovieSetID that matches the current movie sets. That works like a champ, too.

Next, I test the functionality of the form--I can click Add Movie to launch the pop-up form for adding a movie. I can save this movie successfully, but I hit the problem. Because the movie created isn't automatically associated with the MovieSet under which it was created, when the grid refreshes the newly created Movie isn't included in the list (i.e. it's has_one of MovieSet isn't populated with the current MovieSet, in fact it's empty).

Anyone have an idea of how to do this? I'm guessing the HasManyComplexTableField solves this problem by prepopulating the MovieSetID field with the ID of the currently-open MovieSet when it launches the popup form, but I haven't dug into it yet.