Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silverstripe Images Has Many

I'm quite new to Silverstripe and have been playing around with the CMS.

At the moment I'm stuck... I'm trying to add a $has_many relationship between a DataObject and Images.

I'm finding the documentation on doing something like this quite vague? I know that when you want to add a relationship between two DataObjects you need to add a $many_many and $belongs_many_many relationship but how would I do this with images?

I tried adding images to a $has_many and simply using an upload field but this only causes an error. I also tried keeping the images in $has_one and increasing the upload field setAllowedMaxFileNumber to 10 but this only saves 1 image.

Any help in this regard would greatly be appreciated :)

Thanks!

Incase anyone wants to see the code here is a Pastebin

like image 325
Tiaan Swart Avatar asked Oct 20 '22 08:10

Tiaan Swart


1 Answers

You need to many_many image, or have an intermediary object that facilitates images.

This is due to the way that SilverStripe stores a models relationships.

like image 64
user5069360 Avatar answered Oct 21 '22 22:10

user5069360