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

[BUGFIX] AMS polymorphic type for namespaced models #3026

Merged
merged 1 commit into from
May 3, 2015
Merged

[BUGFIX] AMS polymorphic type for namespaced models #3026

merged 1 commit into from
May 3, 2015

Conversation

artych
Copy link

@artych artych commented Apr 26, 2015

Tests and patch fixes #3019

@artych
Copy link
Author

artych commented Apr 26, 2015

I am not sure about typeForRoot function: should it be patched in RESTSerializer or be rewritten in AMS. I decided to rewrite it in AMS since fixed behavior is rails (or ruby) specific.

},

typeForRoot: function(key) {

Copy link
Member

Choose a reason for hiding this comment

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

Extra whitespace here

@igorT
Copy link
Member

igorT commented Apr 27, 2015

I think this looks good.

@@ -166,7 +166,10 @@ var ActiveModelSerializer = RESTSerializer.extend({
if (Ember.isNone(belongsTo)) {
json[jsonKey] = null;
} else {
json[jsonKey] = capitalize(camelize(belongsTo.typeKey));
json[jsonKey] = belongsTo.typeKey.split("/").map(function(part) {
Copy link
Member

Choose a reason for hiding this comment

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

We can't use map here due to IE8 support (I'm not sure when we're dropping it). You can use Ember.EnumerableUtils.map instead.

@fivetanley
Copy link
Member

This also looks good to me but I think we should call this out in CHANGELOG.md and the release blog post. Can you add an entry to the CHANGELOG ?

@artych
Copy link
Author

artych commented Apr 27, 2015

In fact there is no need for map in both cases, it's enough to use replace("::","/") and classify/camelize/underscore conversions. But now classify and camelize doesn't work properly (my opinion):

  Ember.String.classify("evilMinions/yellowMinion");
//=> unexpected "EvilMinions/yellowMinion"
// expected "EvilMinions/YellowMinion"

  Ember.String.camelize("YellowMinions/MiniPig");
//=> unexpected "yellowMinions/MiniPig"
// expected "yellowMinions/miniPig"

 Ember.String.camelize("yellow_minions/mini_pig");
//=> "yellowMinions/miniPig" as expected

I will post new issue if you agree.

@fivetanley
Copy link
Member

Looks like you already added an issue to Ember Inflector. Looks like a bug to me and @stefanpenner emberjs/ember-inflector#77

@artych artych changed the title AMS polymorphic type for namespaced models [BUGFIX] AMS polymorphic type for namespaced models Apr 29, 2015
@artych
Copy link
Author

artych commented Apr 30, 2015

@fivetanley CHANGELOG entry added. Is it good now or I should do something more?

@artych
Copy link
Author

artych commented May 1, 2015

Ember.String issue is moved in ember.js repo just to make this conversation clear.

@@ -2,6 +2,8 @@

### Master

* Fix ActiveModelSerializer serializePolymorphicType and typeForRoot methods for properly serializing and extracting namespaced model names in polymorphic type attributes.
Copy link
Member

Choose a reason for hiding this comment

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

Can you mention the issue name, and also just quickly say it's now accepting :: instead of /

@igorT
Copy link
Member

igorT commented May 2, 2015

Looks, good can you just cleanup the changelog a bit, and I'll merge asap
Thanks!

…racting namespaced model names in polymorphic type attributes. Now AMS accepts '::' istead of '/'. Fixes #3019.
@artych
Copy link
Author

artych commented May 2, 2015

Thank you, @igorT! Changelog entry is changed. This patch should be simplified after fixing emberjs/ember.js#11000.
(UPD: in Ember 1.13)

@@ -166,7 +166,9 @@ var ActiveModelSerializer = RESTSerializer.extend({
if (Ember.isNone(belongsTo)) {
json[jsonKey] = null;
} else {
json[jsonKey] = capitalize(camelize(belongsTo.typeKey));
json[jsonKey] = classify(belongsTo.typeKey).replace(/(\/)([a-z])/g, function(match, separator, chr) {
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps this could be rewritten as classify(belongsTo.typeKey).split('/').map(classify).join('::') ?

Copy link
Member

Choose a reason for hiding this comment

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

Seems fine to me overall though.

fivetanley added a commit that referenced this pull request May 3, 2015
…mespaced-models

[BUGFIX] AMS polymorphic type for namespaced models
@fivetanley fivetanley merged commit 7f86945 into emberjs:master May 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ActiveModelSerializer: wrong polymorphic type processing for namespaced model name
3 participants