Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions /

[Partially Solved] Multiple has_many relationships


Reply


2 Posts   861 Views

Avatar
Mr V Dot

Community Member, 8 Posts

23 January 2011 at 11:09am

Edited: 23/01/2011 11:10am

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

Avatar
Mr V Dot

Community Member, 8 Posts

28 January 2011 at 10:00am

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