Skip to content

Field mapping not working #3

@ArneSaknussemm89

Description

@ArneSaknussemm89

So I still don't quite know enough to know where the problem is, but I'm unable to get any field values off my records after getting them. Here is my current environment.js:

drupalEntityModels: {
  "blog-post": {
    entity: 'node',
    bundle: 'blog_post',
    fields: [
      'blogContent',
      'blogImage'
    ]
  },
  "location": {
    entity: 'node',
    bundle: 'location',
    fields: [
      'locationAddress',
      'locationGeolocation',
      'locationDescription',
      'locationType'
    ]
  },
  "product": {
    entity: 'node',
    bundle: 'product',
    fields: [
      'productDesc',
      'productImages',
      'productType'
    ]
  },
  "product-type": {
    entity: 'node',
    bundle: 'product_type',
    fields: [
      'productTypeCategory',
      'productTypeDesc',
      'productTypeImage'
    ]
  },
  "file": {
    entity: 'file',
    bundle: 'file'
  },
  "user": {
    entity: 'user',
    bundle: 'user'
  },
   "square-image": {
      entity: 'media',
      bundle: 'square_image',
      fields: [
        'squareImageImage'
      ]
    },
    "wide-image": {
      entity: 'media',
      bundle: 'wide_image',
      fields: [
        'wideImageImage'
      ]
    }
  }
};

Here is the model for 'blog-post':

import DS from 'ember-data';

const {
  attr,
  belongsTo,
  Model,
} = DS;

export default Model.extend({
  title: attr('string'),
  blogImage: belongsTo('wide-image'),
  blogContent: attr(),
});

And inside a route I am doing this:

import Ember from 'ember';

export default Ember.Route.extend({
  model: function() {
    return this.get('store').findAll('blog-post');
  }
});

And then when rendering the template I'm doing this:

{{#each model as |blog|}}
  <div class="content">
    {{blog.blogContent}}
  </div>
{{/each}}

But that field is undefined. The title and ID are there, but no field values. If I go inside the ember-data-drupal addon and add console logs inside the service drupal-mapper.js like so:

  entityFor(modelName) {
    console.log(modelName);
    let modelMap = this.map[modelName] || {};
    return modelMap.entity || 'node';
  },

  bundleFor(modelName) {
    console.log(modelName);
    let modelMap = this.map[modelName] || {};
    return modelMap.bundle || modelName;
  },

  fieldName(modelName, fieldName) {
    console.log(modelName);
    let modelMap = this.map[modelName] || {},
        fields = modelMap.fields || [];
    if (fields.includes(fieldName)) {
      return DRUPAL_FIELD_PREFIX + underscore(fieldName);
    }
    return underscore(fieldName);
  }

entityFor and bundleFor both console log out the correct model name, but fieldName console logs out "undefined". This is about as far as I've gotten. Still digging.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions