Unknown hash as model attribute


#1

I have Category model on backend Side (Rails) where category parameters are stored in jsonb type which basically looks like Hash. Those parameters are totally unknown which means that one category can have different parameters types than the other one. I’m trying to fetch them by specifying attribute in model as object but it doesn’t work. Do you know how can I solve this ?


#2

Can you describe the errors? I’m doing something similar for a widget / dashboard app where params is a JSON hash in a Postgres table. It works ok (with some minor issues that I havn’t worked out trying to do observers on the params field) so far.

The serializer looks like this:

class WidgetPageItemSerializer < ActiveModel::Serializer
  attributes :id,
      :controller,
      :action,
      :row,
      :col,
      :width,
      :height,
      :params
end

And the Ember model looks like this:

import Ember from 'ember';
import DS from 'ember-data';

export default DS.Model.extend({
  title:      DS.attr('string'),
  width:      DS.attr('number'),
  height:     DS.attr('number'),
  row:        DS.attr('number'),
  col:        DS.attr('number'),
  controller: DS.attr('string'),
  action:     DS.attr('string'),
  params:     DS.attr()
});

#3

It’s not even error, it’s more like something is wrong with fetching data from server. I’m using ActiveModelAdapter, the example payload looks like this:

 "categories": [
    {
      "id": 1,
      "name": "Sport",
      "parent_id": null,
      "parameters": {
        "minimum age": "Fixnum"
      }
    },

and when I try to get parameters in console I get

> var params = $E.get('parameters');
> undefined
> params
> ember$data$lib$system$model$attributes$$attr(type, options) {
      if (typeof type === "object") {
        options = type;
        type = undefined;
      } else {
        options = options …

Parameters in model are defined as you show.