Hi All,
I had a few questions around the use of simple-schema, collection2 and autoform. DIsclaimer: @aldeed, you are my hero. Questions refer to code below:
let Locations = new SimpleSchema({
locations: { type: Array, label: ‘Location’, optional: true },
‘locations.$’: { type: Object },
‘locations.$.address’: { type: [String], label: ‘Address’, optional: true },
‘locations.$.city’: { type: String, label: ‘City’, optional: true },
‘locations.$.state’: { type: String, label: ‘State’, optional: true },
‘locations.$.country’: { type: String, label: ‘Country’, optional: true },
‘locations.$.zipcode’: { type: String, label: ‘Zip Code’, optional: true }
});
Entities = new Mongo.Collection(‘entities’);
Entities.allow({
insert: () => false,
update: () => false,
remove: () => false
});
Entities.deny({
insert: () => true,
update: () => true,
remove: () => true
});
let EntitiesSchema = new SimpleSchema({
name: { type: String, label: ‘Name’, max: 200 },
description: { type: String, label: ‘Description’,
allowedValues: [‘public’, ‘private’],
autoform: {
options: [
{label: ‘Public Sector’, value: ‘public’},
{label: ‘Private Sector’, value: ‘private’}
]
}
},
locations: { type: Locations, label: ‘Location(s)’ }
});
Questions -
-
With collections in general, in examples (on the web) i see rules around allow/deny for insert, update and remove. (a) Why do we need both allow and deny. I understand it is done as a safety precaution, can someone explain this a little bit more. (b) Why is there nothing for upsert, should this not also be in the rule set if insert, update and remove are there?
-
So while the above code sample works nicely with autoform, what i would like to do is have a seperate table called locations, as in Locations = new Mongo.Collection(‘locations’); but still use it as an external in my entities schema. I have been trying to get it to work, but it crashes out with “(STDERR) ReferenceError: Locations is not defined”.
Is this possible? -
Why do i want to do this? The idea is (say - i made up the example above) i have defined some entities, but i want to add predefined locations to the relevant entities. But i want to use locations in other contexts also. So in my app, a user can add multiple locations to an entity, after defining them. I can handle this in locations by adding a ‘isAssigned’ Boolean or something.
-
More importantly, the next step is to define a simple-schema for Meteor.users as documented in collection2. Then i want to be able to assign users to my entity. This is the use case i am looking to be able to do. So in the app, multiple users can be assigned to a specific entity (i was thinking to do this by having entity specific roles).
Misc Questions:
-
If I do not use Autoform, the model i generally follow is from meteor chef. So allow/deny rules on client side. Fine. But then the client side code calls a module in the server side which does the heavy lifting, so i know my code which makes db changes is not compromised in any way. I do not exactly understand how autoform does this even with the rules in place. [I just started playing with Autoform yesterday]
-
How does pub/sub work with autoform. Say i use an autoform for my entities, as above, but break up into multiple collections (As i want to do). Does the final blaze template subscribe to multiple collections (which is what i’m thinking), or, as the collections have sub collections in them, this is not required.
-
I was also looking at using dburles:collection-helpers but i cannot get my head around the pub/sub concept here. Would the helper not break this?
-
I’m also having some problems trying to move the collections into packages and use AutoForm there. Not sure why… Did anyone else have issues here?
P.S. With the misc questions, i may have confused myself. If someone can explain it out like I’m 5, would be most appreciated.
P.P.S the meteor chef guy is also a champion.
Thanks so much.
Tat