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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Select existing member instead of creating new (modeladmin)


Reply


5 Posts   481 Views

Avatar
esakrielaart

Community Member, 58 Posts

3 January 2012 at 6:05am

Hello all,

I have the following relationship

Class A <--- many_many ---> Member

and it is moderated using the ModelAdmin interface. Now when I create a new Class A object, I wish to select from the new tab 'Member' -> 'Add new Member' an existing Member from a dropdown or similar fashion. However, it shows the form to create a new member. How can I modify this behavior? I suggest I need to change getCMSFields_forPopup() function somewhere?

Any help is highly appreceated.

Friendly regards,
Maurice

Avatar
swaiba

Forum Moderator, 1805 Posts

3 January 2012 at 10:35pm

This is the native way of doing it...

http://doc.silverstripe.org/sapphire/en/tutorials/5-dataobject-relationship-management#project-module-relation

Avatar
esakrielaart

Community Member, 58 Posts

4 January 2012 at 4:03am

Thank you, that is a good start for me. Now I only still do not completely seem to get how to override the save/delete methods from the ComplexTableField. I know I have to override it, so I tried to create a new class:

class SpecialComplexTableField extends ComplexTableField {

}
class SpecialComplexTableField_Popup extends ComplexTableField_Popup {
function saveComplexTableFields() {
die("Notice I am here");
}
}

However I seem to be wrong. What am I doing wrong? Because without changing this, when I delete a row from the CTF, it also deletes the associated Member info!

Thanks in advance,
Maurice

Avatar
swaiba

Forum Moderator, 1805 Posts

4 January 2012 at 4:10am

how to override the save/delete methods from the ComplexTableField

It's not something that is overridden, but you can "hook" into it...

http://doc.silverstripe.org/sapphire/en/topics/datamodel#onbeforewrite

Avatar
esakrielaart

Community Member, 58 Posts

4 January 2012 at 4:24am

Ah thank you, it is coming together now (trying to understand to deeper workings of silverstripe). Really enjoy it and thank you for the support.

Friendly regards,
Maurice