Skip to content
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

Collection2 has no method 'callbacks' #5

Closed
mfjohansson opened this issue Aug 10, 2013 · 3 comments
Closed

Collection2 has no method 'callbacks' #5

mfjohansson opened this issue Aug 10, 2013 · 3 comments

Comments

@mfjohansson
Copy link

The code below gives me the following error message and a meteor chrash:

TypeError: Object [object Object] has no method 'callbacks'
    at app/lib/models.js:X:X
Issues = new Meteor.Collection2("issues", {
  schema: {
    title: {
      label: "Title",
      type: String
    }
  }
});

Issues.allow({
    insert: function() {
        return true;
    },
    update: function() {
        return true;
    },
    remove: function() {
        return true;
    },
    fetch: []
});


Issues.callbacks({
  insert: function(error, result) {
    if (error) {
      return console.log("Insert Error:", error);
    } else {
      alert("Inserted!");
      return console.log("Insert Result:", result);
    }
  },
  update: function(error) {
    if (error) {
      return console.log("Update Error:", error);
    } else {
      return alert("Updated!");
    }
  },
  remove: function(error) {
    return console.log("Remove Error:", error);
  }
});
@aldeed
Copy link
Collaborator

aldeed commented Aug 10, 2013

Are you getting the error on the server? callbacks is only on the client, so that part of your code should only run on the client, whereas the rest of the code can and should be run on both. Wrapping that call in if (Meteor.isClient) { } will probably fix the error.

Also make sure that the collection2 package loads before autoform.

@mfjohansson
Copy link
Author

Thanks, it worked when I wrapped it with isClient since I had the code in my lib-folder.

@aldeed
Copy link
Collaborator

aldeed commented Aug 17, 2013

Good. FYI, and for others who may look at this, I made a change so that there is no longer a server error. Callbacks are not used on the server, so in terms of having logical code organization, I would still recommend defining the callbacks in client code only, but it won't cause an error to put it in shared code going forward.

pouya-eghbali added a commit to pouya-eghbali/meteor-autoform-1 that referenced this issue Mar 30, 2020
pouya-eghbali added a commit to pouya-eghbali/meteor-autoform-1 that referenced this issue Mar 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants