-
-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Enhancement Request]: Ability to define virtual fields within Simple Schema #49
Comments
I understand the use case. Virtual fields are inherently "a collection2 thing" since they rely on transform, but it's possible that we could rethink the options "API" such that they are defined in SS definitions (similar to how Specifically, I'm thinking of something like this: var c = new Meteor.Collection("c", {
schema: new SimpleSchema({
creatorEmail: {
type: String,
virtual: function (doc) {
return getCreatorEmail(doc.createdBy);
}
}
});
}); This would require a way to tell the simple-schema package to ignore definitions that are virtual. I'm not sure I'm sold on doing it yet, but we can keep this open as a proposal. |
You're right, it would also contextually make sense to keep it in c2. As I am progressing on my first "rather complicated" meteor app (coming On 01/16/2014 08:07 PM, Eric Dobbertin wrote:
|
Oh, now I get this. Brilliant! On 01/16/2014 08:07 PM, Eric Dobbertin wrote:
|
@serkandurusoy, after checking out the code for the collection-helpers package, I'm thinking about deprecating virtual field support entirely and having people use that package instead. I think it's a better method. I also opened an issue for a collection-helpers enhancement which, if added, would I think meet your needs. |
Sounds very logical and I'm sure everyone would benefit from the gains introduced by such decision. |
A powerful feature of Collection2 is the ability to define schema structure outside the collection definition.
Coupled with the ability to combine multiple schema structures within Simple Schema, we have a good mechanism for keeping the code dry, abstract and clean.
Virtual fields are a great addition to Collection2. But consider a use case where we have a base schema (e.g. createdAt, createdBy, updatedAt, updatedBy) which we include in all our collections through their respective schemas.
And consider for each document in any collection, I would like to have a virtual field that gives me the email address for the user who has created the document.
In its current form, we need to include such virtual field in every collection or hack it using _.extend etc.
It would be a great feature if one could define virtual field at the schema level as well.
The text was updated successfully, but these errors were encountered: