Closed ccorcos closed 10 years ago
You are right, it doesn't. I have been thinking about that before, and I'm not sure how to do it. Imagine the next scenario: a webapp multi-user. If you want to be sure the user inserts a reference that belongs to him, you maybe have to check for the userId. What do you think?
Well, the custom validation is the simplest way of ensuring proper validation. But I was just thinking something as simple as making sure it is a valid object in another collection:
if (Authors.findOne()) { return true}
Another field could be something like noRepeats
which would ensure that in an array of authors, there are no repeats. This logic could also be used with selectize to make sure the correct options are displayed...
I'd love to help by the way, I'm just having trouble digging into the auto form, collection2, and simple-schema code...
I've coded the next:
window = @
SimpleSchema.addValidator ->
if Meteor.isServer
if @definition.references?
references = @definition.references
a = references.split('.')
collection = a[0]
collection = window[collection]
if collection.findOne @value
return true
else
return 'Error Foreign Key.'
else
return true
else
true
Is it more or less what you expect? You can see it in the selectize branch.
exactly
Looking at the code, it doesn't seem that the ForeignKey is validated is it?