C1 Orckestra - Can a Global Datatype have a 1 to many relationship?

75 views Asked by At

Is it possible to create a global datatype that has a 1 to many relationship?

Example

Create a global datatype for Dogs (some object on the website) 
ID is a unique 8 character random string 
Each Dog has several properties. (color, size, and so on) 
Each Dog has many pictures. (as many as you would like, 1toMany)

I can see how you can assign a "C1 Media Folder" to a field, but what we are trying to achieve, is when you are editing the Dog's data (or adding a new one), you can add as many pictures as you want at this moment. It would be nice if the media folder was created at the moment the new Dog's data object is created, and it uses the unique ID from them Dog object to name the Media Folder. This gets us close to what we want, but it still means you have to jump over to the Media Library to upload the images you want tied to the Dog object.

If this is not possible with the current C1 console, does the C1 API allow us to code our own methods for adding images to the media library?

Thank you.

1

There are 1 answers

1
Pauli Østerø On

Your question seems to me to be not 100% specific, many things going on here which all should have its own question.

To answer what i see as the primary question based on the title, the answer is that you can do it in two ways.

  1. Your pictures-field of the Dog object would contain a comma-separated list of media-item ids. This is the "C1" way of doing a 1-many relation and is what all the build-in multi-selector widgets in the C1 console supports.

  2. Create a separate relationship holder object, call it DogPictureRelation which has a reference to a Dog objects and a Media object. And maybe a LocalOrdering field if the order of the pictures matters. This is the more correct way in a database world -we call it a relationship table, but unfortunately the built-in widgets don't support this and you would have to create your own Pictures-selector widget do work with this kind of datastructure.