3093 Posts in 875 Topics by 654 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1165 Views |
-
One-to-one relations with ModelAdmin

28 February 2010 at 12:41am Last edited: 28 February 2010 11:21am
Using the ModelAdmin I would like to implement one-to-one relations, but am unsure how to tell ModelAdmin the way to represent it.
The partial data model is:
Resumes --< Education +--- Address
So a resume could have many education records, and each of those records may have a single address of the establishment (university, school, college, etc.).
Using the standard ModelAdmin screens, the Education record is edited in a pop-up. However, the address is then selected in a drop-down of addresses, which effectively implements a one-to-many (addresses to education records). How would I go about making this one-to-one, perhaps having the address as a second tab on the education pop-up? Since there is a "Main" tab there, I assume it is possible to add further tabs.
How would saving the data then work? Would both records (education and address) be submitted and saved at the same time? What about clashes of field names - would the "Name" of the Address get mixed up with the "Name" of the education record?
Attached: screen shot of the education tab, showing the address drop-down that should actually be a single form.
-- Jason
-
Re: One-to-one relations with ModelAdmin

25 March 2010 at 10:37pm
http://open.silverstripe.org/ticket/4034
http://open.silverstripe.org/changeset/90072This is in trunk, but you can easily work around it in 2.4 already by defining a $has_one on one side, and doing a custom getter on the other side.
class Education { static $has_one = array('Address' => 'Address'); }
class Address { function getEducation() { return DataObject::get_one('Education', sprintf('"AddressID" = %d', $this->ID)); }}
-
Re: One-to-one relations with ModelAdmin

25 March 2010 at 10:42pm Last edited: 25 March 2010 10:42pm
That's nice and simple. I did find a slightly more involved solution to this on 1.3 and posted it on another thread.
However, I can't find that thread now - any idea how to display all the threads started by an individual? My profile page only shows the last ten.
-- Jason
-
Re: One-to-one relations with ModelAdmin

25 March 2010 at 10:51pm
Don't think there's a way for displaying all threads by person, but perhaps @willr can work his magic if you file a well-described ticket for it on http://open.silverstripe.org/query?status=inprogress&status=new&status=replyneeded&status=reviewed&component=Modules+-+forum&order=priority&col=id&col=summary&col=status&col=type&col=priority&col=milestone&col=component
-
Re: One-to-one relations with ModelAdmin

26 March 2010 at 1:42am
Feature request duly raised.
And here is the previous thread that shows how to include a 1:1 data object as a second tab in the parent data object, and have both saved at the same time when the user submits the form:
http://www.silverstripe.org/general-questions/show/279948
-- Jason
| 1165 Views | ||
|
Page:
1
|
Go to Top |


