Hi all
Am trying to link 2 entities together via it's ID, via a 1-N (one to many) relationship (should be simple).
So I have pages1
and pages2
, and I want page1 to have many page2
linked. So I put in page2
a field parent
and use a select
(via autoform) to link it.
Problem: cannot make it work. First the type of object wasn't accepted. Now this code is the closest I can get, but my meteor app doesn't update/save anything and there are no error message.
Here is the pages1.js and pages2.js entities declaration files :
page1.js
// 1st level pages
orion.addEntity('pages1', {
title: {
type: String,
label: "Titre"
},
content: orion.attribute('froala', {
label: "Contenu"
})
}, {
icon: 'bookmark',
sidebarName: 'Page niveau 1',
pluralName: 'Pages1',
singularName: 'Page1',
tableColumns: [
{ data:'title', title: 'Titre' },
{ data:'content', title: 'Contenu' }
]
});
page2.js
// 2nd level pages
orion.addEntity('pages2', {
title: {
type: String,
label: "Titre"
},
content: orion.attribute('froala', {
label: "Contenu"
}),
image: orion.attribute('file', {
label: 'Image',
optional: true
}),
liens: {
type: [String],
label: "Liens",
optional: true
},
articles: orion.attribute('file', {
label: 'Article',
optional: true
}),
parent: {
type: [Object],
autoform: {
// type: "select2", // FIXME: specifying SELECT2 type makes an error
afFieldInput: {
multiple: true
},
options : function() {
return orion.entities.pages1.collection.find().map(function (obj) {
return {
label: obj.title,
value: obj._id
};
});
},
},
label: 'Parent',
optional: true
}
}, {
icon: 'bookmark',
sidebarName: 'Page niveau 2',
pluralName: 'Pages2',
singularName: 'Page2',
tableColumns: [
{ data:'title', title: 'Titre' },
{ data:'content', title: 'Contenu' }
]
});
Do you have any idea why this ain't working? Maybe a better way to make relationships like this work?
Thanks in advance for your help and advice!
Cheers