Jump to:

3432 Posts in 1058 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » [Partially Solved] Multiple has_many relationships

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

Page: 1
Go to End
Author Topic: 770 Views
  • Mr V Dot
    Avatar
    Community Member
    8 Posts

    [Partially Solved] Multiple has_many relationships Link to this post

    Hi, I'm trying to set up a ticket system and need to be able to have one ticket have multiple 'related tickets' which are organized in a specific order. My basic idea was to create an 'OrderedSupportTicket' object which just has one field for sort order, along with as has_one relationship to a specific ticket. The problem is that it also needs a has_one to the parent ticket. Since it's clearer to understand what I'm saying in code, here's the relevant parts:

    class SupportTicket extends DataObject {
    ...
    static $has_many = array(
    'OrderedTickets' => 'OrderedSupportTicket.ParentTicket',
    'OrderingTickets' => 'OrderedSupportTicket.SubTicket',
    );
    ...
    }

    and

    class OrderedSupportTicket extends DataObject {
    ...
    static $has_one = array(
    'ParentTicket' => 'SupportTicket',
    'SubTicket' => 'SupportTicket',
    );
    ...
    }

    All of that works fine for the database, but cannot be managed via a HasMany(CTF/DOM) field. As soon as I set one of the 'SupportTicket' relationships on the OrderedSupportTicket object, it becomes un 'checkable' in the hasmany field, and as soon as I save it it's marked as no longer belonging to the ParentTicket.

    I realize that if need be I can just create my own 'SubTicketID' field and write a getter/setting combo to take care of that, but ideally I'd prefer to use the sapphire framework as it's supposed to be. Thanks for any and all suggestions,
    Alex

  • Mr V Dot
    Avatar
    Community Member
    8 Posts

    Re: [Partially Solved] Multiple has_many relationships Link to this post

    I managed to partially solve the problem. By reordering the 'has_one' relationships on the 'OrderedSupportTicket' class, and making the 'ParentTicket' element last, the CTF table now uses the correct relationship for the checkboxes. It seems like this is a bit of a hack fix, but it will work for now. Please send any suggestions anyone might have on how more properly to implement this.
    Thanks,
    Alex

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