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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

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

Trouble adding has_many children

Go to End

2 Posts   1016 Views


Community Member, 2 Posts

23 March 2012 at 3:23am

Hi all

Bit of a newbie question, I'm sure, but I just can't find a solution to this problem. I suspect it's something I'm doing wrong but...

OK, I have a parent class with a has_many relationship with a child class. SilverStripe/Sapphire creates the tables correctly but I'm not able to insert any child objects into the database using SS. The steps I'm expecting to work for me are...

1. create new Parent object
2. get Children component set
3. create Child objects and use add() to add them to Children
4. call write() on Parent to write Parent and Children to database

I'm not getting any error messages that I can find but nor am I getting any Child objects inserted into the database. I've done my best to find useful example code, read the documentation, etc. but I'm just stuck.

Could someone please point me at a complete example of achieving the above or highlight where I'm going wrong?

Thanks in advance


Community Member, 72 Posts

27 June 2012 at 2:44am

Are you trying to do this on a front end form or in the CMS? I am doing something similar, but I'm trying to build out a front end form that will input the child relationships as well.