Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Member object and Data objects

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

Page: 1
Go to End
Author Topic: 926 Views
  • meganub
    Avatar
    Community Member
    15 Posts

    Member object and Data objects Link to this post

    Hi Guys,

    I've set up a site and I'm currently plumbing in some custom functionality - one of the things I need to do is add some fields and data to the member object. As such I've:

    • Extended the Member using a DataObjectDecorator
    • Created two data objects, both of which hold trivial data (lets call them Foo and Bar)
    • Created a many to many relationship between Member and my two data objects - I.e. all of my members can be associated with any or all of the data objects
    • Used 2 ManyManyComplexTableField in updateCMSFields on the aforementioned DataObjectDecorator to display/edit the relationships in the Member pop up view.

    Now, my problems are that when I view a member, I can't add a new Foo or Bar as there is no "Add new Foo" button. I've gotten around this by instead of going through the pop up in security (when you click on a user), going straight to the following page in my browser:

    /admin/security/EditForm/field/Members/item/2/edit

    This has allowed me to create Foo's and Bar's as much as I want, and they now show up on both the direct (above URL) and regular (view Security) Member views. However I can't associated my Member (heh) with any of the Foo or Bar's I have created - I check the boxes, save, it's saves without errors but no associations are created. I've double checked in the database.

    So my question is basically: Is associating data objects with Members even possible, or have I missed the big entry in the wiki that states "Members can't be associated with Data objects you fool".

    Cheers

    Robbie

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Member object and Data objects Link to this post

    Firstly I have not tried many_many for extending the members so this is just thoughts

    I'd use the great http://www.silverstripe.org/multiselectfield-module/ to be able to "re-use" and set up this many_many relationship.

    Also I extend the member using...

    _config.php

    Object::add_extension('Member', 'CustomMember');

    CustomMember.php

    class CustomMember extends DataObjectDecorator {

       function extraStatics()
       {
          return array(
             'has_many' => array(
                'Foo' => 'Foo',
             ),
          );
       }
    }

    Hope this helps!

  • meganub
    Avatar
    Community Member
    15 Posts

    Re: Member object and Data objects Link to this post

    Hi Swaiba,

    Thanks for your help. I've actually already done that part of work - it's after that point that I have the issues with creating new "Foo" objects, and then associating them with Members.

    Cheers

    Robbie

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Member object and Data objects Link to this post

    Oh, well I would normally use ModelAdmin for all CRUD operations so for the Foo and Bar info to be selectable in the MultiSelect you could use code like...

    for each data object...

    class Foo extends DataObject
    {
    static $db = array('fielda'=>'Text');
    }

    to CRUD the records in the Many Many thing...

    class FooBarAdmin extends ModelAdmin
    {
       static $managed_models = array(
    'Foo',
    'Bar',
       );

       static $url_segment = 'foobaradmin';
       static $menu_title = 'Foo Bar Admin';
    }

    Is that what you are after?

  • meganub
    Avatar
    Community Member
    15 Posts

    Re: Member object and Data objects Link to this post

    Hi Swaiba,

    Cheers for that, it's given me a good idea for a plan B!

    Basically my issue is adding data objects against a Member - I.e. is it possible? I'm increasingly thinking it isn't. The system picks up on them, but the CRUD operations seem broken.

    Cheers

    Robbie

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Member object and Data objects Link to this post

    Well it is a double edged sword - assuming there are no complications with CTF and having popups - as I think about it...

    with the multi select and have a nice chooser, but this only selects existing objects
    with the main sapphire scaffolding you get the tabs and the add button, but this then wont let you share Foo and Bar objects created there with others...

    oh and have you tried putting 'Member' into your managed models in a Model Admin? this would mean the first has_many would be on a tab, not in a tab of a popup

  • meganub
    Avatar
    Community Member
    15 Posts

    Re: Member object and Data objects Link to this post

    I'll give that approach a try, failing that, there is a plan b I can tackle it with.

    Cheers for all your help

    Robbie

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