Jaro
Jaro

Reputation: 990

What is proper way to fill fields which are auto generated depending on other ones

I'm using AutoForm for forms and SimpleSchema with Collection2 to schema.

In my schema there are some fields which are generated during document insert/creation and are able to change later on.

When it's the best place to generate data and put into database?

  1. Write needed code using autoValue directly in schema.
  2. Use AutoForm Hooks.
  3. Do it using matb33:collection-hooks before/after.insert hooks.

What's are pluses and minuses in each case?

Upvotes: 0

Views: 62

Answers (1)

Dennis Stolmeijer
Dennis Stolmeijer

Reputation: 122

I Would say the following:

  1. Use autoValue by default if you want set or change a specific field.
  2. The AutoForm hooks are specific for forms and not used as global hooks.
  3. matb33:collection-hooks are perfect if you want to trigger some logic which isnt specific for a field.

typically I use autoValue for automatically setting the loggedInUser, createdAtDate, updatedAtDate.. etc and I use matb3:collection-hooks for example when I create a user and and I automatically want to create a event log in the database.

Hope it helps you.

Upvotes: 0

Related Questions