dimanche 14 août 2016

Ember.js with Firebase backend: change default database entry names for dynamic routes

I'm building a personal website with Ember.js and Firebase (EmberFire) as the backend. I've got Firebase connected and I can createRecords and such, and then view the records in the Firebase console.

I'm building my own post system for my website for personal posts and whatnot. I would like to have a dynamic route for my posts at /posts/:post_id, where :post_id is the dasherized title of the post. I've been following the Ember tutorial and already have all the attributes I need (like a dasherized title) in my model. However, whenever I create a record and send the data to the Firebase database, Firebase automatically generates a post id like so:

posts
 -KP3SRMcfGCXW1hz-c1W
 -KP3a-6nr9C_gqPMTnFO
 -KP53U2pxOZw1gCewBXM
 -KPAde4QmamjrrNpVhhn
 -KPAeXaxty4p5uWbBvE8
 -KPAetgYyKFZMVCl9h9l
 -KPAh0JZt6GvLqhpEnIG
 -KPAh8vrKNaPLYZGbkvq

So if I have a post called "hello first post", I can't go to /posts/hello-first-post, but if that post has ID -KPAh8vrKNaPLYZGbkvq, I could go to /posts/-KPAh8vrKNaPLYZGbkvq and it would work. I've already generated the dynamic route which is why the latter option works.

I am wondering how I can change this so that I can have the dynamic route for posts NOT be the auto-generated id by Firebase.

For example, I want this to work:



I already have a post route which routes to /posts/:post_id, so the link-to helper is generating the correct link. But there is nothing there because Firebase has it's auto-generated post ID.




Aucun commentaire:

Enregistrer un commentaire