Login | Forgot password | Register

X

What is OpenID?

OpenID is an Internet-wide identity system that allows you to sign in to many websites with a single account.

With OpenID, your ID becomes a URL (e.g. http://username.myopenid.com/). You can get a free OpenID for example from myopenid.com.

For more information visit the official OpenID site.

Jump to:

2506 Posts in 739 Topics by 544 members

Customising the CMS

SilverStripe Forums » Customising the CMS » many many relationship and ModelAdmin

Page: 1
Go to End
Author Topic: many many relationship and ModelAdmin 871 Views
  • Jean-Phi
    avatar
    Community Member
    12 posts

    many many relationship and ModelAdmin Link to this post

    Hi,

    I've just install SilverStripe 2.3 RC2 and I'm trying the real interesting new feature : ModelAdmin

    It work real properly with one to many relationship but doesn't work with many_many.

    Here are my classes :

    final class Book extends DataObject
    {
    static $db = array(
    'Label' => 'Varchar',
    'ISBN' => 'Varchar',
    );
    static $has_one = array(
    'author' => 'Author'
    );
    static $searchable_fields = array(
    'Label',
    'ISBN',
    );
    static $summary_fields = array(
    'Label',
    'ISBN',
    'author'
    );
    static $belongs_many_many = array(
    'categories' => 'Category',
    );
    }
    final class Category extends DataObject
    {
    static $db = array(
    'label' => 'Varchar',
    );

    static $many_many = array(
    'books' => 'Book',
    );
    }

    Here is the code for model admins :

    class BookAdmin extends ModelAdmin
    {

    protected static $managed_models = array(
    'Book'
    );

    static $url_segment = 'books';
    static $menu_title = 'Admin books';

    }
    class CategoryAdmin extends ModelAdmin
    {

    protected static $managed_models = array(
    'Category'
    );

    static $url_segment = 'categories';
    static $menu_title = 'Admin categories';

    }

    When I've build my db and flush everything I can see Category tab on Book's edit view, but can't add categories on it.
    Is something wrong with my code?

  • Jean-Phi
    avatar
    Community Member
    12 posts

    Re: many many relationship and ModelAdmin Link to this post

    Thanks all for your aswers, such a reactive community!

  • UncleCheese
    avatar
    Forum Moderator
    2667 posts

    Re: many many relationship and ModelAdmin Link to this post

    Well, sheesh... you asked a question during the biggest vacation week of the year.

    I'm just barely getting my feet wet with the ModelAdmin. I love the idea, but it seems like there's a lot of room for refinement. It wouldn't surprise me if handling complex relationships like many-to-many is something that's just out of its reach right now. I'm actually not sure it will even be included with the official 2.3 release.

    My suggestion would be to just go back to using a CTF like the old days.

  • Jean-Phi
    avatar
    Community Member
    12 posts

    Re: many many relationship and ModelAdmin Link to this post

    Hello,

    thanks for your aswer but I saw in 2.3 changelog : ModelAdmin

    I've download the 2.3 RC (Release Candidate means that all new features are allready implemented...)

    So I think I'll look back to symfony for complex models.

    See you latter!

  • henning.blunck
    avatar
    Community Member
    6 posts

    many many relationship and ModelAdmin: Not that easy Link to this post

    Hey Everyone,
    I'm in the same situation as Jean-Phi is/was and am encountering the very same problems.
    I'm quite sure that this is a bug and I (and Jean-Phi) have worked properly. Even the sample code from the german SilverStripe Book does not work properly there (I refer to the Developer <-> Skills Relationship).
    Hopefully, they'll get that fixed, though I've not yet found a corresponding entry in the Trac System. The only way to get it (more or less) working at the moment is to explicitely define the CMS-Fields (using getCMSFields() and ManyManyComplexTable) after that, the existing records are listed.

    Henning

    PS: I'm using Silverstripe 2.3.1 "stable" release

  • Ingo
    avatar
    Administrator
    596 posts

    Re: many many relationship and ModelAdmin Link to this post

    Hey guys, I can confirm this broken behaviour. It was fixed in trunk 2 months ago, I'm hoping to get it merged to a 2.3.x minor release: http://open.silverstripe.com/ticket/3927

    The fix will still only let you add new records, not associate a many_many with existing records (which you can do with ManyManyCTF), but its a start.

    Particularly embarrassing as this demo code made it into the german book! Sorry for the trouble, we messed this one up - if we provide a scaffolder for certain relationship types, they should work out of the box at least in the most basic way.

    871 Views
Page: 1
Go to Top

Currently Online: Dramew, silk

Welcome to our latest member: holy noli

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

Comments on this website? Please give feedback.