Comments (3)
Or is there another way this is supposed to work? Should I be providing some sort of extra template? The examples are pretty light when it comes to saving/fetching nested models.
from backbone-mongo.
Hello!
I've taken a look at your code and see that there are some conventions that need to be followed (some undocumented):
-
Add callbacks are of the form "(err, result) ->" - that means "fetch(function(om2) {})" should be "fetch(function(err, om2) {})"
-
The naming convention for models are:
a) urls are underscored, pluralized: "/innermodel" should be "/inner_models"
b) relationships are also underscored, but either pluralized or singularized depending on the relationship plurality: "innerModel" should be "inner_model"
-
Because the embedded relationship is stored on the OuterModel, the relationship should be "belongsTo" instead of "hasOne".
Other things
-
Instead of using a url on the InnerModel, you could add a property 'model_name: "InnerModel"' to it (with CoffeeScript in Node, model_name and url are optional).
-
The function around a relationship is only necessary for breaking dependency cycles so "innerModel: function(){return [...]}" could be simplified to "inner_model: [...]"
-
We typically don't use the fetch mechanic, but findOne:
OuterModel.findOne om.id, (err, om3) ->
assert.deepEqual(om3.get('inner_model').attributes, om.get('inner_model').attributes)
You can find a working version of your code here. Also, I will update the documentation to make the conventions more clear.
Just let me know if you have any more problems.
from backbone-mongo.
@kmalakoff omg thank you so much for going through this! I'm going to go over it and implement the changes :)
Hope you had an excellent holiday!
from backbone-mongo.
Related Issues (15)
- toJSON doesn't serialize attached models HOT 1
- After an error emitted by mongo, queries do not return
- Fix intermittent test failures HOT 2
- Ids that look like numbers should not be parsed as if they are numbers HOT 1
- Should _rev be an optional feature?
- $unique does not work properly with $page
- Promise feature request HOT 2
- Frontpage example has error? HOT 1
- Multiple calls to Model#set don't cause change triggers to fire HOT 4
- Can't have it working with node.js modules HOT 3
- MongoDB connection remains open HOT 5
- Multiple calls to unset causes only the last attribute unset to be unset HOT 2
- Sorting by ids doesn't work HOT 2
- Browserify breaks with inflection HOT 2
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 backbone-mongo.