Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Confused by complextablefield

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 1702 Views
  • jam13
    Avatar
    121 Posts

    Confused by complextablefield Link to this post

    I'm trying to setup a table called "FeaturedRecipe" (by extending DataObject) with the following relations:

    $has_one = array (
    'Image' => 'Image'
    'Recipe' => 'RecipePage'
    );

    which works fine. But I now want to be able to edit that table in the CMS in a tab in a RecipeHolder page (parent page for all recipes).

    I can't use a normal tablefield because they don't work with Images, so I'm trying to use a complextablefield. The problem is which type to use. This is how I understand their use:

    hasmanycomplextablefield - when one RecipeHolder has many FeaturedRecipes - uses checkboxes to select which FeaturedRecipes are related
    hasonecomplextablefield - when one RecipeHolder has one FeaturedRecipe - uses radio buttons to select which FeaturedRecipe is related

    The problem is that neither of these fit because there is only one RecipeHolder page and it has _no_ relationship with FeaturedRecipes - I just want to be able to edit the whole (unfiltered) table within it's tabs.

    So I looked at the parent class complextablefield, which I assumed required no relationship with RecipeHolder, but it keeps complaining that it can't find the parent class and that I should set it with setParentClass.

    Looking at the code it seems that it's looking for a has_one relationship, but I don't see how this could work when there's no apparent way of selecting this relationship in the table (no radio buttons or checkboxes).

    Can someone explain how one would use complextablefield except as a base class for the other variations?

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: Confused by complextablefield Link to this post

    choosing ComplexTableField (CTF) instead of the subclasses is probably a good idea - we need to document the differences better and guide users with their choice. the CTF subclasses are actually pretty new and not often implemented, we usually implement the base-class.

    you're placing the field on RecipeHolder->getCMSFields(), right?
    as a $sourceClass, you should pass FeaturedRecipe.
    if you want to display all items regardless of relation, just leave out the $sourceFilter.

    i'm afraid CTF isn't built for the case of having a loose collection of items without a parent-relation. the easiest solution would be to specifiy the relation to the holder expicitly: setParentClass('RecipeHolder') and a $has_one RecipeHolder on FeaturedRecipe.

  • jam13
    Avatar
    121 Posts

    Re: Confused by complextablefield Link to this post


    you're placing the field on RecipeHolder->getCMSFields(), right?
    as a $sourceClass, you should pass FeaturedRecipe.
    if you want to display all items regardless of relation, just leave out the $sourceFilter.

    That's what I'm doing.


    i'm afraid CTF isn't built for the case of having a loose collection of items without a parent-relation. the easiest solution would be to specifiy the relation to the holder expicitly: setParentClass('RecipeHolder') and a $has_one RecipeHolder on FeaturedRecipe.

    I tried that, but I still couldn't get it to work. The closest I got was to set a $has_one in both classes (one-one relationship), but although this seemed to work it placed an empty "RecipeHolderID" entry in every FeaturedRecipe and so ended up working like a broken has_many!

  • jam13
    Avatar
    121 Posts

    Re: Confused by complextablefield Link to this post

    Ok, I'm trying a different tack.

    Is it possible to get the hasmanycomplextablefield checkbox magic using tablefield (or even tablelistfield)?

    1702 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.