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

TypeError: Ember.A(...).mapBy is not a function #3466

Closed
billpull opened this issue Jun 29, 2015 · 18 comments
Closed

TypeError: Ember.A(...).mapBy is not a function #3466

billpull opened this issue Jun 29, 2015 · 18 comments

Comments

@billpull
Copy link

Getting this error after loading a payload via store.query()

TypeError: Ember.A(...).mapBy is not a function at ember$data$lib$system$record$arrays$record$array$$default.extend.loadRecords (adapter-populated-record-array.js:54)

Ember: 1.13.2
Ember-Data: 1.13.4

@wecc
Copy link
Contributor

wecc commented Jun 29, 2015

Hey @billpull! What does your payload look like and what serializer are you using? Would you be able to put together a JSBin demonstrating this issue? Makes it much easier to debug.

@liamcoau
Copy link

liamcoau commented Jul 3, 2015

@wecc I'm getting this as well. It's a blocking issue and I can't load any routes.
Shown here is the payload, after normalizeResponse, and the error.
screenshot from 2015-07-03 13 16 32

import Ember from "ember";
import DS from "ember-data";

export default DS.RESTSerializer.extend({
    isNewSerializerAPI: true,

    normalizeResponse: function (store, type, payload, id, requestType) {
        //console.log('normalizeResponse', arguments);

        for (var key in payload.data.links) {
            if (typeof payload.data.links[key] == "object")
                payload.data.links[key] = payload.data.links[key].related;
        }

        // Example type: Skilltapper@model:user:
        // Goal is to just get "user"
        var model = type.toString();
        var new_payload = new Object();

        Ember.assert("First part of type is not 'skilltapper@model:' in <" + model + ">", model.slice(0,18) == "skilltapper@model:");
        Ember.assert("Last char of type is not ':' in <" + model + ">", model.slice(model.length-1) == ":");

        model = model.slice(18, model.length - 1);
        new_payload[model] = payload.data;

        return this._super(store, type, new_payload, id, requestType);
    },

    normalize: function (typeClass, hash, prop) {
        console.log("normalize");
        console.log(hash);
        return this._super(typeClass, hash, prop);
    },

    normalizeHash: {
        links: function (hash) {
            console.log("Got the links hash");
            return hash;
        }
    }
});

here's the serializer I have, also, Ember @1.13.0 and Ember-Data @1.13.4 and ember-cli @0.2.7

@liamcoau
Copy link

liamcoau commented Jul 3, 2015

Perhaps the issue is that records should be an array but here it is a class?
screenshot from 2015-07-03 14 20 52

@liamcoau
Copy link

liamcoau commented Jul 3, 2015

@billpull and @wecc Issue resolved by using queryRecord instead of query. It was not very clear that I should have used queryRecord instead, it just said find was deprecated and I should switch to query.

@jorgelainfiesta
Copy link

@liamcoau I was also getting this error when using query, but when I tried queryRecord I get an error saying

Uncaught Error: Assertion Failed: You tried to make a query but your adapter does not implement `queryRecord`

I am using the default RESTAdapter with no custom serializer or anything fancy. Did you have to implement queryRecord by yourself?

@liamcoau
Copy link

liamcoau commented Jul 4, 2015

Yes, I implemented queryRecord on my adapter. I also implemented urlForQueryRecord.

@jorgelainfiesta
Copy link

@liamcoau thanks, I'll do that then. I thought it was a default method in RESTAdapter.

@billpull
Copy link
Author

billpull commented Jul 5, 2015

@liamcoau can you link me to an example of your adapter implementation
On Jul 4, 2015 3:27 PM, "Liam Coleman-Aulenbach" [email protected]
wrote:

Yes, I implemented queryRecord on my adapter. I also implemented
urlForQueryRecord.


Reply to this email directly or view it on GitHub
#3466 (comment).

@liamcoau
Copy link

liamcoau commented Jul 5, 2015

Here's the full adapter:
http://pastebin.com/1EJRygXF

Here's an example of how it's called:

var user = _this.store.queryRecord("user", {
  "id": _this.session.content.auth_id,
  "include": "skills,job_title"
});

I had to do some "munging" with the id, since I needed to pass that along but the third parameter is a snapshot (not actually sure how that's supposed to be used?)...
Anyways it produces a url such as:
http://example.com/user/2lkj3l5l2jkl25j5?access_token=dkasjf43j3224256swrte&include=skills,job_title

@liamcoau
Copy link

liamcoau commented Jul 5, 2015

@billpull also I know you should avoid this.session.content.etc if you can in favour of session.get("etc")

@wecc
Copy link
Contributor

wecc commented Jul 7, 2015

queryRecord should have been implemented in RESTAdapter, sorry about that. It's tracked in #3514

We should probably assert an array in finders/_query or AdapterPopulatedRecordArray.loadRecords.

@liamcoau would you like to provide a PR adding an assert?

@liamcoau
Copy link

liamcoau commented Jul 8, 2015

Sure!

@IsaiahJTurner
Copy link

Is there a solution to this?

@bmac
Copy link
Member

bmac commented Oct 13, 2015

@IsaiahJTurner what version of Ember Data are you using? I believe this bug was fixed in ember-data 1.13.7.

@btecu
Copy link
Contributor

btecu commented Oct 15, 2015

I'm getting this error as well when I use query but findAll doesn't trigger the error.
Ember Data 2.x.

@bmac
Copy link
Member

bmac commented Oct 15, 2015

@btecu do you mind sharing a stack trace for this error?

@btecu
Copy link
Contributor

btecu commented Oct 15, 2015

Error while processing route: photos Ember.A(...).mapBy is not a function TypeError: Ember.A(...).mapBy is not a function
    at ember$data$lib$system$record$arrays$record$array$$default.extend.loadRecords (http://dev/assets/vendor.js:58891:47)
    at http://dev/assets/vendor.js:58509:21
    at tryCatch (http://dev/assets/vendor.js:51508:14)
    at invokeCallback (http://dev/assets/vendor.js:51523:15)
    at publish (http://dev/assets/vendor.js:51491:9)
    at http://dev/assets/vendor.js:30141:7
    at Queue.invoke (http://dev/assets/vendor.js:1224:16)
    at Object.Queue.flush (http://dev/assets/vendor.js:1288:11)
    at Object.DeferredActionQueues.flush (http://dev/assets/vendor.js:1089:17)
    at Object.Backburner.end (http://dev/assets/vendor.js:378:25)

TypeError: Ember.A(...).mapBy is not a function
    at ember$data$lib$system$record$arrays$record$array$$default.extend.loadRecords (adapter-populated-record-array.js:56)
    at finders.js:160
    at tryCatch (ember.debug.js:51306)
    at invokeCallback (ember.debug.js:51321)
    at publish (ember.debug.js:51289)
    at ember.debug.js:29939
    at Queue.invoke (ember.debug.js:1022)
    at Object.Queue.flush (ember.debug.js:1086)
    at Object.DeferredActionQueues.flush (ember.debug.js:887)
    at Object.Backburner.end (ember.debug.js:176)

@btecu
Copy link
Contributor

btecu commented Oct 15, 2015

@bmac If the stack trace is not enough, I could probably create a repository with this issue.

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

7 participants