Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Many To Many on the same object #3113

Closed
clemblanco opened this issue May 7, 2014 · 7 comments
Closed

Many To Many on the same object #3113

clemblanco opened this issue May 7, 2014 · 7 comments

Comments

@clemblanco
Copy link

I can't have a many to many relation working on the same object.

For example I have a Product object. I want this product to be linked to other products so I tried to put:

'RelatedProducts' => 'Product'

in my many_many attribute and then I tried to create a GridField to manage the link between them by using:

$RelatedProductsField = GridField::create(
'RelatedProducts',
'Related Products',
$this->RelatedProducts(),
GridFieldConfig_RelationEditor::create()
);
$fields->addFieldToTab('Root.RelatedProducts', $RelatedProductsField);

But I get the PHP error saying:
Fatal error: Call to a member function stat() on a non-object in /path-to-server/sitename/framework/model/DataObject.php on line 3231

@tractorcow
Copy link
Contributor

Why did you put 'RelatedProduct' => 'Product' and not 'RelatedProducts' => 'Product'?

@clemblanco
Copy link
Author

Was a typo my bad. Sorry but it's not the solution.

@kinglozzer kinglozzer added the 3.1 label Oct 25, 2014
@wernerkrauss
Copy link
Contributor

is this issue related to #1377 ?

@adrian-stein
Copy link

This is still an issue and I am getting the exact same error. Is there any news on when it will be getting fixed?

See this example With related products extending the swipestripe module product class.

<?php
class ProductExtension extends DataExtension{
    private static $many_many = array(
        'RelatedProducts' => 'Product'
    );

    private static $belongs_many_many = array(
        'IsRelatedTo' => 'Product'
    );

    public function updateCMSFields(FieldList $fields) {
        $gridField = GridField::create('RelatedProducts',
            'Related Products',
            $this->owner->RelatedProducts(),
            GridFieldConfig_RelationEditor::create()
        );

        $fields->addFieldToTab('Root.RelatedProducts', $gridField);
    }
}

If I change $this->owner->RelatedProducts() with say CartPage::get() it works fine and the page loads otherwise I get the above error.

@tractorcow
Copy link
Contributor

Fixed with #3799

@adrian-stein
Copy link

@tractorcow do you know when is this getting released in a stable version?

@dhensby
Copy link
Contributor

dhensby commented Aug 12, 2016

A bit late, @adrian-stein but this is in 3.2.0+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants