Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4830

Urls - problem with using this.store.query in model hook

$
0
0

@therealbenhogan wrote:

Hi,

I want to include parameters in my urls which together determine which record to display rather than just relying on the (id) primary key.

So

/page/slug or /posts/dd/mm/yyyy/slug

rather than

page/id or posts/id

It’s obviously important (in the posts example here) that all parameters in url are taken into account in finding the record, not (for example) just the slug.

Therefore I can’t use this.store.findRecord() or this.store.peekRecord. The primary key in my backend models is the ID and for the moment, I don’t want to change this.

Instead I am using this in model hook (simpified just to use the slug in this case)

return this.store.query('someModelName',{
		filter: {
			slug: params.slug
		}
	}).then(function(result) {
		return result.get("firstObject");
	});

However, when I run this route I get a “Type error can’t convert this to string” alert in the console and navigating between routes gives the same record back.

What I am doing wrong here?

Using the default DS.JSONAPIAdapter.

Many thanks

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4830

Trending Articles