Coder Social home page Coder Social logo

Comments (3)

lukejagodzinski avatar lukejagodzinski commented on May 19, 2024

Right now I would discourage you from modifying Astronomy objects on publication. Astronomy objects can't be sent over DDP right now, and I will be working on it soon. It's on my TODO list. Astronomy objects have to EJSONable to allow that. However if you really want to do this there is a way. Here are changes you have to make to your code:

First change is the transform function. I've commented CHANGES.

var transform = function(doc) {
  // YOU HAVE TO GET SIMPLE OBJECT FROM ASTRONOMY OBJECT USING GET() FUNCTION
  var obj = doc.get();

  var lastMessage = Messages.findOne({
    chatId: obj._id
  }, {
    sort: {
      createdAt: -1
    },
    // YOU HAVE TO TURN OF AUTOMATIC DOCUMENTS TRANSFORMATION
    transform: null
  });

  obj.lastMessage = lastMessage;

  return obj;
};

You have also modify your Chat class schema to have lastMessage field.

Chat = Astronomy.Class({
  name: 'Chat',
  collection: Chats,
  fields: {
    title: {
      type: 'string'
    },
    // THE lastMessage FIELD HAS TO BE DEFINED IN THE SCHEMA
    lastMessage: {
      type: 'object'
    }
  }
});

Thanks to that, you will receive all the objects as you want. However when you call:

var chat = Chats.findOne();
console.log(chat); // Astronomy object.
console.log(chat.lastMessage); // Not Astronomy object!

You won't get Astronomy object calling chat.lastMessage it's because there are not relations defined. It's also on my TODO list because it's closely related to EJSONinification of Astronomy documents.

from meteor-astronomy.

banglashi avatar banglashi commented on May 19, 2024

Thanks a lot for the quick reply and the explanation, appreciate it. Keep up the good work and let me know if I can help with anything.

from meteor-astronomy.

lukejagodzinski avatar lukejagodzinski commented on May 19, 2024

No problem :). I'm glad that you and others are testing this package. Thanks to that I can move it forward to the point where it will be fully usable and fit almost all needs. If you want to help, please watch this and other Astronomy repositories so you will be notified about new issues. I will be adding new issues with discussion label, to talk about new features and how to implement them the way developers want it to be.

Regards :)

from meteor-astronomy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.