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

How to get the "modelName" of a polymorphic relationship "belongsTo"

$
0
0

@Myrdhin wrote:

My models:

// Attachment model
export default DS.Model.extend({
});

// Image Model
import Attachment from './attachment/model';
export default Attachment.extend({
  src: DS.attr('string)
});

// Doc Model
import Attachment from './attachment/model';
export default Attachment.extend({
  filename: DS.attr('string')
});

// Email Model
export default DS.Model.extend({
  title: DS.attr('string'),
  attachment: belongsTo()
});

In my template, i would like to identify the attachment's modelName... If my Email has an Image, i can use {{email.attachment.src}}. It's OK. If it's a Doc attachment, {{email.attachment.filename}} works. No problem.

But, when i try to display attachment modelName, i can't... I try:

  • {{email.attachment.constructor.modelName}}
  • {{email.attachment.content.constructor.modelName }}

Only last ( {{email.attachment.content.constructor.modelName }}) works. Why ? I know belongsTo relationship is a DS.PromiseObject so I thought it was possible to use {{email.attachment.constructor.modelName}} !? Why not ?

Thanks for your help.

Posts: 3

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 4830

Trending Articles