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

Fixes deprecation warnings for ember-data beta.15 #111

Merged
merged 7 commits into from
Jun 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"jquery": "1.11.1",
"ember": "1.8.1",
"ember-data": "1.0.0-beta.15",
"qunit": "1.17.1"
"qunit": "~1.17.1"
}
}
16 changes: 5 additions & 11 deletions dist/ember-couchdb-kit.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/ember-couchdb-kit.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion spec/document-adapter_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ test 'retrieve belongsTo field as raw json', 1, ->
person = @subject.create.call @, 'user', id: Math.floor(Math.random() * 10000), name: 'john'
message = @subject.create.call @, 'message', user: person
message.save().then @async ->
equal message.get('_data.user.id'), person.get('name'), 'Retrieves raw belongsTo json ok'
equal message.get('_data.user'), person.get('name'), 'Retrieves raw belongsTo json ok'

test 'hasMany relation', 1, ->
article = @subject.create.call @, 'article', label: 'Label'
Expand Down
29 changes: 15 additions & 14 deletions spec/env.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -115,30 +115,31 @@ window.setupStore = (options) ->
env = {}

options = options or {}
container = env.container = new Ember.Container()
registry = new Ember.Registry(options)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please provide your Ember version? Well, all my tests are failed due to switching to Ember.Registry instead of using Ember.Container as first is undefined on 1.8.1.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was using 1.11.0 for the test suite

container = env.container = registry.container()
adapter = env.adapter = EmberCouchDBKit.DocumentAdapter.extend db:'doc', host: 'http://localhost:5984'

delete options.adapter

for prop of options
container.register "model:" + prop, options[prop]
registry.register "model:" + prop, options[prop]

container.register "store:main", DS.Store.extend adapter: adapter
registry.register "store:main", DS.Store.extend adapter: adapter

container.register "serializer:_default", EmberCouchDBKit.DocumentSerializer
container.register "serializer:history", EmberCouchDBKit.RevSerializer
container.register "serializer:attachment", EmberCouchDBKit.AttachmentSerializer
registry.register "serializer:_default", EmberCouchDBKit.DocumentSerializer
registry.register "serializer:history", EmberCouchDBKit.RevSerializer
registry.register "serializer:attachment", EmberCouchDBKit.AttachmentSerializer

container.register "adapter:_rest", DS.RESTAdapter
container.register "adapter:history", EmberCouchDBKit.RevAdapter.extend db:'doc', host: 'http://localhost:5984'
container.register "adapter:attachment", EmberCouchDBKit.AttachmentAdapter.extend db:'doc', host: 'http://localhost:5984'
registry.register "adapter:_rest", DS.RESTAdapter
registry.register "adapter:history", EmberCouchDBKit.RevAdapter.extend db:'doc', host: 'http://localhost:5984'
registry.register "adapter:attachment", EmberCouchDBKit.AttachmentAdapter.extend db:'doc', host: 'http://localhost:5984'

container.register 'transform:boolean', DS.BooleanTransform
container.register 'transform:date', DS.DateTransform
container.register 'transform:number', DS.NumberTransform
container.register 'transform:string', DS.StringTransform
registry.register 'transform:boolean', DS.BooleanTransform
registry.register 'transform:date', DS.DateTransform
registry.register 'transform:number', DS.NumberTransform
registry.register 'transform:string', DS.StringTransform

container.injection "serializer", "store", "store:main"
registry.injection "serializer", "store", "store:main"

env.serializer = container.lookup("serializer:_default")
env.restSerializer = container.lookup("serializer:_rest")
Expand Down
2 changes: 1 addition & 1 deletion spec/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<script src="/bower_components/qunit/qunit/qunit.js"></script>
<script src="/bower_components/handlebars/handlebars.js"></script>
<script src="/bower_components/jquery/dist/jquery.js"></script>
<script src="/bower_components/ember/ember.js"></script>
<script src="/bower_components/ember/ember.debug.js"></script>
<script src="/bower_components/ember-data/ember-data.js"></script>
<script src="/dist/ember-couchdb-kit.js"></script>
<!-- env setup and assertions -->
Expand Down
14 changes: 5 additions & 9 deletions src/document-adapter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,18 @@ EmberCouchDBKit.DocumentSerializer = DS.RESTSerializer.extend
serializeBelongsTo: (record, json, relationship) ->
attribute = (relationship.options.attribute || "id")
key = relationship.key
belongsTo = Ember.get(record, key)
belongsTo = record.belongsTo(key)
return if Ember.isNone(belongsTo)
json[key] = Ember.get(belongsTo, attribute)
json[key + "_type"] = belongsTo.constructor.typeKey if relationship.options.polymorphic
json[key] = if (attribute == "id") then belongsTo.id else belongsTo.attr(attribute)
json[key + "_type"] = belongsTo.typeKey if relationship.options.polymorphic

serializeHasMany: (record, json, relationship) ->
attribute = (relationship.options.attribute || "id")
key = relationship.key
relationshipType = record.constructor.determineRelationshipType(relationship)
relationshipType = record.type.determineRelationshipType(relationship)
switch relationshipType
when "manyToNone", "manyToMany", "manyToOne"
if record.get(key).get('content.isLoaded') || Ember.get(record, key).get('isLoaded')
json[key] = Ember.get(record, key).mapBy(attribute)
else
if record.get("_data.%@".fmt(key))
json[key] = record.get("_data.%@".fmt(key)).mapBy('id')
json[key] = record.hasMany(key).mapBy(attribute)
###

A `DocumentAdapter` should be used as a main adapter for working with models as a CouchDB documents.
Expand Down