Jump to:

3376 Posts in 1000 Topics by 713 members

Data Model Questions

SilverStripe Forums » Data Model Questions » 2 related DataObject w/ ModelAdmin for directory

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

Page: 1
Go to End
Author Topic: 485 Views
  • Wolfbane
    Avatar
    Community Member
    5 Posts

    2 related DataObject w/ ModelAdmin for directory Link to this post

    Hi

    I'm new to Silverstripe (though not to other CMS flavors) so if someone could take pity on me that would be great! (Edit, I have been reading over the docs and I am still not making the connection).

    I'm trying to build a directory of categories/businesses in Silverstripe which seems to be pretty straightforward using DataObject, however, things are getting tricky because I don't have a set number of categories so I'm trying to use ModelAdmin to manage them both.

    My thinking so far has been to create two DataObjects (category & business) and then to relate them to each other:

    class Category extends DataObject {
    static $db = array(
    'Name' => 'Varchar(128)'
    );

    static $belongs_many_many = array(
    'Businesses' => 'RecycleDirectory'
    );
    }

    class RecycleDirectory extends DataObject {

    static $db = array(
          'Name' => 'Varchar(255)',
          'Address' => 'Varchar(255)'
    );
    static $many_many = array(
    'Categories' => 'Category'
    );

    Using ModelAdmin to manage the values:

    class DirectoryAdmin extends ModelAdmin {

    public static $managed_models = array(
    'RecycleDirectory',
    'Category'
    );
    static $url_segment = 'DirectoryAdmin';
    static $menu_title = 'Recycling Directory';
    }

    The two issues I'm having are:

    1. In ModelAdmin I'm seeing a tab labeled categories (hurray) but I'm not seeing existing categories show up as already selected. Further, I can only add a category (which gives me a form to create a new one) and visa versa when I look at a category I see a "businesses" tab, but when I add to it I get a form to create a new entry instead of select from existing. (See attached)

    2. This one is really bothering me: with the Category being a DataObject, I can't figure out how I would then show each Category on the frontend and populate each one with their associated business entries. I would expect to need to set up some sort of association between the Page->DataObject (or to create the page in the CMS and associate businesses to it)

    Can anyone shed some light on this?

    Thank you in advance!

    Attached Files
  • swaiba
    Avatar
    Forum Moderator
    1769 Posts
  • Wolfbane
    Avatar
    Community Member
    5 Posts

    Re: 2 related DataObject w/ ModelAdmin for directory Link to this post

    Still looking through postings and such.. I'm not sure that a 3rd party module is what I really want to be using, however, maybe I should be looking at using a ManyManyComplexTableField to manage my relationship?

    As far as the 2nd link.. that doesn't get me closer to creating a page with a URL for each DataObject as that suggests making an actual page and associating the DataObjects with them.. :-/

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: 2 related DataObject w/ ModelAdmin for directory Link to this post

    I'm not sure that a 3rd party module is what I really want to be using, however, maybe I should be looking at using a ManyManyComplexTableField to manage my relationship?

    Certainly ManyManyComplexTableField is in fact what ModelAdmin scaffolds for you and you can create a custom one in getCMSFields and set various options to change it's behaviour... however having had the exact same problem 2 years ago and having used the external module to solve it since then - I am sure.

    As far as the 2nd link.. that doesn't get me closer to creating a page with a URL for each DataObject as that suggests making an actual page and associating the DataObjects with them.. :-/

    you previously said...

    I would expect to need to set up some sort of association between the Page->DataObject

    i agreed and pointed you to a tutorial that you did just that, in case it isn't obvious a Page is inherited from (and thereby equivalent to) a DataObject. To associate the page with the dataobject is straightforward once you have gone through he tutorials. If you are saying you'd prefer to not associate the page with the data object but rather have a single page that is passed parameters to so a specific dataobject then you might try this... http://archive.ssbits.com/using-silverstripe-url-parameters-to-display-dataobjects-on-a-page

  • Wolfbane
    Avatar
    Community Member
    5 Posts

    Re: 2 related DataObject w/ ModelAdmin for directory Link to this post

    You just blew my mind a little bit.
    I'm going to dig into the module (which scares me coming from Drupal and Magento background) but if you say that it'll do the magic I need..

    Regarding the latter, you just blew my mind a little bit more.

    I'll report back with any updates but I really, really want to thank you for your time in helping a new guy get started with SS.

    Matthew

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