Comments (8)
class App.collections.people extends backbone.collections.
Colelections != Collection. Seems like a simple typo to me.
from backbone-relational.
Grr, sorry. Unfortunately, that's not the problem - the typo was introduced when I typed up the issue; my actual CoffeeScript file had it correct. To clarify code that (for me) fails is:
class App.Collections.People extends Backbone.Collection
model: App.Models.Person
url: '/api/people'
class App.Collections.Companies extends Backbone.Collection
model: App.Models.Company
url: '/api/companies'
#`App.Collections.People = Backbone.Collection.extend({
# model: App.Models.Person,
# url: '/api/people/'
#});
#
#App.Collections.Companies = Backbone.Collection.extend({
# model: App.Models.Company,
# url: '/api/companies/'
#});`
But this works (using backticks to pass raw JS through the CS compiler):
#class App.Collections.People extends Backbone.Collection
# model: App.Models.Person
# url: '/api/people'
#
#class App.Collections.Companies extends Backbone.Collection
# model: App.Models.Company
# url: '/api/companies'
`App.Collections.People = Backbone.Collection.extend({
model: App.Models.Person,
url: '/api/people/'
});
App.Collections.Companies = Backbone.Collection.extend({
model: App.Models.Company,
url: '/api/companies/'
});`
And I've triple checked that that is the precise code I actually used to create the error, this time. :) Thoughts?
from backbone-relational.
Hmm, this type of crazy stuff is why I tend to stay away from intermediate languages being compiled into another language, that gets compiled into.. etc ;).
How does collection.create
behave? Do that actually make proper new persons/companies, instead of plain Backbone.Model
instances (which is the default)?
from backbone-relational.
Does the problem exists in coffeescript 1.1.2? I've written some production code in the past and coffeescript class extension worked flawlessly.
If not, then it's a backbone-relational bug that was introduced in master
, because I've used 0.4.0.
from backbone-relational.
Paul Uithol: Yeah, I decided to try Backbone.js for the first time, and in an excess of enthusiasm, node.js and CoffeeScript, all on the same project. Maybe I should have tried a more incremental approach. sigh
Regardly, while creating a simple test case, I figured out the problem: As I believed was best practice, I was splitting up my Backbone project into different files for models, collections, and views, and then running coffee -j on the source tree to generate a single app.js file. This worked great, right up until it didn't. It turns out the CoffeeScript compiler was sticking my collections above my models in the compiled JS file. (Of course, every time I wrote some test code, I put it all in the same file - so my simple test cases always worked, but my "real" code never did. This also explains why my "hack" to define collections in pure JS worked - I was putting it in a different file, which was getting compiled into the "right" place. FML.)
Anyhow, if I put collections and models in the SAME CS file like this:
class App.Models.Person extends Backbone.RelationalModel
urlRoot: '/api/people'
class App.Collections.People extends Backbone.Collection
model: App.Models.Person
url: '/api/people'
then I can do:
>people = new App.Collections.People()
People
>people.model
function Person() {
Person.__super__.constructor.apply(this, arguments);
}
>people.create({name: 'me'})
Person
Presto, everything works. But if I do this:
class App.Collections.People extends Backbone.Collection
model: App.Models.Person
url: '/api/people'
class App.Models.Person extends Backbone.RelationalModel
urlRoot: '/api/people'
Then I get:
> people = new App.Collections.People()
People
> people.model
undefined
> people.create({name: 'me'})
TypeError: undefined is not a function
sigh Damn but that wasted about uh...three days of my time. I love the CoffeeScript syntax, but I guess I'm seeing your point about intermediate languages.
Thanks a ton for your help; that question about collection.create was the clue I needed. >< I'm marking this as closed since it doesn't seem to be a bug at all, much less a bug with your excellent code.
from backbone-relational.
@codyhatch have you tried @brunch? It was designed to support backbone & coffeescript out-of-box, with a nice modularity (require.js support etc). I've used backbone-relational with it, every model / collection had a separate file for it.
from backbone-relational.
@paulmillr Thanks for the pointer. Looks interesting, although the documentation is a little contradictory re: what node version it supports, etc. Also, does it currently support any templates other than Eco?
from backbone-relational.
yup, the docs need some updates.
brunch 0.8 supports node 0.4 & eco, brunch 0.9-beta (I'll release in a couple days) supports jade, eco, mustache & node 0.4/0.6. 0.9 also has nice api for custom languages e.g. haml etc.
from backbone-relational.
Related Issues (20)
- Backbone send null for unset relations HOT 1
- Backbone Relational dealing with model instances with the same ID HOT 2
- Retain model in collection when unsetting on another relationship HOT 1
- Models without id (only cid) are not registered in Backbone.Relational.Store HOT 1
- Doesn't work with lodash 4.1.0 HOT 1
- Is this project abandoned? HOT 6
- Backbone 1.3.2 support HOT 2
- using toJSON to serialize data HOT 3
- Update documentation for ES2015/CommonJS importing
- JSBin example HOT 1
- Rename Backbone-relational to backbone.relational HOT 4
- Double imports for using with webpack HOT 5
- ES2015 Refactor (Release Checklist) HOT 1
- Store causing huge memory retention and cleanup takes forever HOT 2
- How do I get Backbone-relational working with ES6? HOT 6
- Problem defining relations: "model does not inherit from Backbone.RelationalModel" HOT 6
- getAsync() fails when retrieving to many models using set URL HOT 4
- don't initialize related Model/Collection in defaults HOT 2
- Collection instances share `options` object by reference which is unexpected
- Backbone-relational compactibility with typescript
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-relational.