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

Id that are Number should update with an Id as a string #1450

Closed
narf opened this issue Oct 15, 2013 · 2 comments
Closed

Id that are Number should update with an Id as a string #1450

narf opened this issue Oct 15, 2013 · 2 comments
Assignees

Comments

@narf
Copy link

narf commented Oct 15, 2013

Tested with beta 3

This cause inconsistensy with my Db where ids are Numbers, all insert requests with belongsTo don't pass the validation process (the ref must be a number but ember cast it to a string).

I can understand that you need internally to play with strings, but why not keeping the base type for all queries? There is propably a way to do this like defining the type of the belongsTo, or maybe the type of the primary key for you to cast it before querying...

line 1174:

// Implementors Note:
//
//   The variables in this file are consistently named according to the following
//   scheme:
//
//   * +id+ means an identifier managed by an external source, provided inside
//     the data provided by that source. These are always coerced to be strings
//     before being used internally.
//   * +clientId+ means a transient numerical identifier generated at runtime by
//     the data store. It is important primarily because newly created objects may
//     not yet have an externally generated id.
//   * +reference+ means a record reference object, which holds metadata about a
//     record, even if it has not yet been fully materialized.
//   * +type+ means a subclass of DS.Model.

// Used by the store to normalize IDs entering the store.  Despite the fact
// that developers may provide IDs as numbers (e.g., `store.find(Person, 1)`),
// it is important that internally we use strings, since IDs may be serialized
// and lose type information.  For example, Ember's router may put a record's
// ID into the URL, and if we later try to deserialize that URL and find the
// corresponding record, we will not know if it is a string or a number.
var coerceId = function(id) {
  return id == null ? null : id+'';
};
@igorT
Copy link
Member

igorT commented May 28, 2014

You could override serializeBelongsTo to cast the strings as numbers. I think there should probably be an easier hook to handle this but not sure how exactly it should look: whether it should only be a one hook for both primaryKey and relationships.

@igorT igorT self-assigned this May 28, 2014
@igorT
Copy link
Member

igorT commented May 25, 2015

Closing as a duplicate of #3078

@igorT igorT closed this as completed May 25, 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

No branches or pull requests

2 participants