Comments (3)
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.
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.
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)
- [Feature request] Mongo transactions HOT 2
- Class.create - create not found HOT 1
- [Feature Request] doc.save() return a promise HOT 3
- Q: is there an afterFieldSet event? HOT 1
- Feature: mongo Deciamal type HOT 6
- Strange behaviour of the method 'save' within the helper
- Updating "sub class" isn't working HOT 1
- advice on indexes on 'type' HOT 2
- This package is still maintenance? HOT 2
- Getting field definition HOT 2
- findOne with fields causes insert on optional field HOT 1
- delete field on subtype? HOT 1
- Integrating Astro class with meteor/ostrio:files HOT 9
- Is there a way to use the validator without a document/model? HOT 1
- Method "Astronomy/execute" not found 404 HOT 3
- Trigger another field validation error HOT 4
- Detect if a field was hidden in afterInit event HOT 3
- How to mock meteor method call when declaring method in class? HOT 2
- Issues with latest Meteor versions & oplog converter
- Standalone version HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from meteor-astronomy.