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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Using ManyManyDataObjectManager on the belongs_many_many side


Go to End
Reply


25 Posts   5669 Views

Avatar
MarcusDalgren

Community Member, 288 Posts

9 July 2009 at 7:44pm

Hello.

I have been trying to use the ManyManyDataObjectManager on both sides of the many-many relationship but when I try to load a page that has the belongs_many_many-relationship I get an empty javascript alert and then it says "Error loading the page". The ManyManyComplexTableField has the same behaviour so this is probably inherited from there.

Isn't it supposed to work on both sides?
I am trying for a setup where products and accessories are related to eachother. They are both pages so I want the user to be able to specify the relationship if they're creating a product or an accessory. Right now the only possible way to manage the relationship is through the product page which gets a bit clumsy.

I will also be adding a third page to the mix later and then it will be even more important to be able to set the relationship from both sides.

Kindly, Marcus

Avatar
UncleCheese

Forum Moderator, 4096 Posts

10 July 2009 at 1:34am

The belongs_many_many part of the relationship should be a descendant of DataObject, not SiteTree. So I'm not sure what you mean when you say you're looking at it from the other side, unless you're in ModelAdmin, maybe?

Avatar
MarcusDalgren

Community Member, 288 Posts

10 July 2009 at 1:51am

Does it really matter if it's a descendant of DataObject or not?
Well of course it matters in some way since it doesn't work, but the other DataObjectManagers work on Sitetree and Sitetree inherits DataObject so Sitetree is a DataObject too.

I have the relationships working now by using checkBoxSetField on the belongs_many_many-side. This solution was bugging before and that's why I tried using the ManyManyDataObjectManager on the belongs_many_many pages.

To explain what I'm trying to do, I have two page types that are related to eachother, Products and Accessories. Products have the relationship $many_many and Accessories has the $belongs_many_many. The reason I tried this is because I want to be able to define the relationships when I make the Accessory, not just on the product side.

Anyways, it's only the ManyManyDataObjectManager and it's ComplexField equivalent that throw the error, it actually kind of works if you use the hasManyDataObjectManager on the belongs_many_many-side. You can't actually manage the relationship but the DataObjectManager shows up and doesn't give an error.

What I am thinking is that this is some kind of bug since you get an empty javascript dialog. Could you point me to the code that figures out what it's supposed to be fetching or is there some other way I can see what is happening and causing the error?

I really think that the manymany-managers (yours and the original) should work if you're using it on the page that has $many_many or on the page that has the $belongs_many_many. After all, it should be pretty much the same functionality, the connection table is there after all and all that should have to be done is reverse it.

The scenario I am working from here is that even though one is $many_many and the other one is $belongs_many_many the system needs to treat them more equal than in a has_one -> has_many. I pretty much have it working now with the checkBoxSetField but your DataObjectManager looks alot cooler ;)

Avatar
UncleCheese

Forum Moderator, 4096 Posts

10 July 2009 at 2:04am

I would start by just finding out what the error is. Turn on error reporting via email, look at the result of the AJAX request in Firebug. There are a number of things you can do to figure out what the error is. An empty alert box isn't much to go on.

Avatar
MarcusDalgren

Community Member, 288 Posts

10 July 2009 at 2:06am

Yes I will go digging and report back what I find!

Avatar
Chris Dangerfield

Community Member, 8 Posts

4 September 2009 at 2:13pm

Just wanting to know if you solved this one. I am having exactly the same difficulty.

Avatar
MarcusDalgren

Community Member, 288 Posts

4 September 2009 at 7:23pm

No, I went for the checkBoxSetField solution since I was short on time and didn't have the time to troubleshoot it. Thanks for reminding me though, I actually have some spare time nowadays so I'll have a look at this and see if I can figure it out.

I'll try to report back today with my findings.

Avatar
MarcusDalgren

Community Member, 288 Posts

5 September 2009 at 2:11am

Ok I have started tracing this.

Fixing ManyManyComplexTableField is pretty simple. For some reason the code for figuring out which table to hit when it's a belongs_many_many is wrong. Simply replace the if statement that begins on line 28 or thereabouts with this:

if( isset( $belongsManyManyRelations ) && array_key_exists( $this->name, $belongsManyManyRelations ) ) {
   $newSingleton = singleton($belongsManyManyRelations[$this->name]);
   $relationships = $newSingleton->uninherited('many_many', true);
   $tie = array_search($controller->ClassName, $relationships);
   $this->manyManyParentClass = $class;
   $manyManyTable = $belongsManyManyRelations[$this->name] . '_' . $tie;
   break;
}


This code will find the correct table to link up to. However ManyManyDataObjectManager seems to choke on some other error as well that occurs somewhere in the DataObjectManager base class. I am still tracking this error but the above code should tide you over with the ManyManyComplexTableField until I find and fix this.

Go to Top