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.

Archive /

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

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

Confused by complextablefield


Reply


4 Posts   1780 Views

Avatar
jam13

121 Posts

11 October 2007 at 1:55am

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?

Avatar
Ingo

Forum Moderator, 801 Posts

11 October 2007 at 7:50am

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.

Avatar
jam13

121 Posts

11 October 2007 at 9:49am


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!

Avatar
jam13

121 Posts

12 October 2007 at 4:56am

Ok, I'm trying a different tack.

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