Replies: 24 comments
-
We do not provide any specific support in our adapter. What issues are you running into? |
Beta Was this translation helpful? Give feedback.
-
I've done some of my own testing and it seems we do not currently support polymorphic relationships. The records are saved into their own collections, which defeats the purpose of polymorphism, and an error shows when trying to reload the relationships:
|
Beta Was this translation helpful? Give feedback.
-
Yes, I ran into this same issue. I was hoping the polymorphic relationships were supported, but as you have pointed out, it looks as though this is not the case. |
Beta Was this translation helpful? Give feedback.
-
I'd love to have this working. I'm a newbie to firebase, but have some experience drilling down into ED serializers. I assume, at a high level, that records simply need to be saved into their own collections with a |
Beta Was this translation helpful? Give feedback.
-
I agree with you. I'm not terribly experienced in either firebase or ember data, but when I was working with polymorphic relationships in ember data and I would create a child record, the ember inspector would show record creation of both the child and parent with the same firebase ID simultaneously. This was helpful in allowing you to reference the child object from the parent class. Having a similar implementation in emberfire would definitely be helpful. Sent from my iPhone
|
Beta Was this translation helpful? Give feedback.
-
@molligan I think however this feature is implemented, that behaviour in the ember inspector would remain the same. I dug around in the adapter and serializer and made some hack-ish progress, but I'm not sure how to go about it in the following case:
In I'm sure there's other design decisions as well that need to be made before polymorphism can really be supported. |
Beta Was this translation helpful? Give feedback.
-
+1 for polymorphism support i'm new to firebase but i love the idea of ember-cli firebase :) full stack goodness. |
Beta Was this translation helpful? Give feedback.
-
@tstirrat did some investigation, looks like Problem with current firebase is
my "fix":
|
Beta Was this translation helpful? Give feedback.
-
+1 for polymorphic relationships. I assumed that this would be included and it's causing me some major issues with my data modeling. @wolfbiter do you have any suggestions on adding hasMany polymorphism? |
Beta Was this translation helpful? Give feedback.
-
+1 for polymorphism. Firebase is awesome but I would like to have full support of all EmberData features. |
Beta Was this translation helpful? Give feedback.
-
+1. Just could say the same as @alejandrocarlos . |
Beta Was this translation helpful? Give feedback.
-
I've started looking into this, and it is a bit complicated, but it should be possible. I'm unsure if this is fit for being part of the official EmberFire adapter, and if so it needs to be optional, as implementing it will break current sites that might have polymorphic data in multiple tables. Most implementations do handle this on the server side as well, since allowing the client to push 'any' type into the store, might cause application issues. E.g. if you have the following Pet = DS.Model.extend({
name: DS.attr('string'),
type: DS.attr('string')
});
Dog = Pet.Model.Extend({
type: 'dog';
})
Cat = Pet.Model.Extend({
type: 'cat';
}) The client can potentially change the code to push type of 'donkey' into the store, and if so, your application might/will error when loading the data. Ember Data polymorphic associations assume one endpoint per model, and assumes the polymorphic storage to be handle server-side and not client side. A recommended talk on the subject: https://vimeo.com/115987599 The simplest solution is to override the pathForType and look for either a The implementation should briefly be:
I will try to make the changes and do a PR, however it will take time. Please provide comments/thoughts on the subject. |
Beta Was this translation helpful? Give feedback.
-
Any preference if polymorphic STI should be default, opt-in or opt-out through configuration? |
Beta Was this translation helpful? Give feedback.
-
I'd say it should be default with the option to opt-out. |
Beta Was this translation helpful? Give feedback.
-
I'd say opt-out through configuration. |
Beta Was this translation helpful? Give feedback.
-
After a week + a bit of testing, here's a few findings. Polymorphic STIEmber Data assumes polymorphic STI records to have separate endpoints. Example: Shape = DS.Model.extend({}); // endpoint shapes
Circle = Shape.Model.extend({}); // endpoint circles
Rectangle = Shape.Model.extend({}); // endpoint rectangles It is possible to force loading/storing circles and rectangles through shapes, so it will appear as single table inheritance storage, however, when you do these steps: (Assuming patch for path/type is properly set up) Create record c = store.createRecord('circle');
c.save() // saves to /shapes/ (assuming id = 1) Find record // Find shape with id 1, will load into circle, since type = 'circle'. Will load from backend/firebase.
store.find('shape', 1) Triggering find again store.find('shape', 1)
// Will load from backend/firebase again, since ED knows that it does not have a shape with ID 1. So this breaks caching of objects in the ED store. I still haven't solved how to do this properly in the store. If anyone has suggestions on how to fix this both for the adapter and for the ED store, please provide feedback. Polymorphic relationships.Example: Taggable = DS.Model.extend({
tags: DS.hasMany('tag', {async:true})
});
Post = Taggable.Model.extend({
tags: DS.hasMany('pet', {async: true, polymorphic: true} )
});
Image = Taggable.extend({
tags: DS.hasMany('pet', {async: true, polymorphic: true} )
});
Tag = DS.Model.extend({
taggable: DS.belongsTo('taggable', {async:true, polymorphic: true})
}); This seems to work out of the box. The last combination is STI with polymorphic relations, and that cannot be solved before I've figured out more of the details on fixing STI for firebase. All examples i've come accross implements botht eh STI endpoint and the model specific endpoints, so ember-data and the adapter does not have to be 'monkey-patched'. I still think it's fixable on the adapter side, but it takes time to solve properly. @tstirrat Are there any configuration options on the serverside to e.g. morph/copy data when it's recieved on one endpoint? Or does everything have to be client-side? |
Beta Was this translation helpful? Give feedback.
-
Seems like STI can be problematic. See emberjs/data#2407 |
Beta Was this translation helpful? Give feedback.
-
RFC on emberjs/ember-data emberjs/rfcs#67 |
Beta Was this translation helpful? Give feedback.
-
Hi there! |
Beta Was this translation helpful? Give feedback.
-
Hi Carlos, we don't support polymorphic relationships in EmberFire at the moment. We're waiting on clearer directions in the underlying Ember Data. |
Beta Was this translation helpful? Give feedback.
-
Ember data 2.6 will have a new ids-and-type strategy which may lays parts of the groundwork needed for this to be possible. See http://emberjs.com/blog/2016/05/03/ember-data-2-5-released.html#toc_upcoming-features-in-ember-data-2-6-beta-1 |
Beta Was this translation helpful? Give feedback.
-
Any update on this? Thank you. |
Beta Was this translation helpful? Give feedback.
-
@tpetrone Have to wait for emberjs/rfcs#67 |
Beta Was this translation helpful? Give feedback.
-
Does emberfire support polymorphic ED relationships? I have tried searching on the web, and doing a few implementations but I have run into trouble. I just want to make sure that polymorphic relationships are indeed supported.
Beta Was this translation helpful? Give feedback.
All reactions