Jump to:

22972 Posts in 11596 Topics by 2824 members

General Questions

SilverStripe Forums » General Questions » Custom HasManyComplexTableField/HasManyDataObjectManager with filter -- adding new items

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

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

Page: 1
Go to End
Author Topic: 1545 Views
  • jackson_gabbard
    Avatar
    Community Member
    13 Posts

    Custom HasManyComplexTableField/HasManyDataObjectManager with filter -- adding new items Link to this post

    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 set's. 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 fix this/set that field automatically in the pop-up? 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.

  • jackson_gabbard
    Avatar
    Community Member
    13 Posts

    Re: Custom HasManyComplexTableField/HasManyDataObjectManager with filter -- adding new items Link to this post

    One step closer--setting the relationAutoSetting on the HasManyDataObjectManager gets me part of the way there. By setting it to true, the created Movie will automatically get assigned a MovieSet of the one currently being managed. The only thing this doesn't do then is assign the newly created Movie as checked within the MovieSet has_many relation. Basically, the goal is to be able to create a new Movie and have both the current MovieSet and the Movie created reference eachother automagically.

  • Paco728
    Avatar
    Community Member
    28 Posts
    1545 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.