Skip to content

Instantly share code, notes, and snippets.

@bj-mcduck
Last active August 29, 2015 13:58
Show Gist options
  • Save bj-mcduck/10343650 to your computer and use it in GitHub Desktop.
Save bj-mcduck/10343650 to your computer and use it in GitHub Desktop.
attr = DS.attr
App.DreamSymbol = DS.Model.extend
image: attr 'string'
name: attr 'string'
description: attr 'string'
user: DS.belongsTo 'user'
parents: DS.hasMany('dream_symbol', { embedded: 'always' })
children: DS.hasMany('dream_symbol', { embedded: 'always' })
siblings: DS.hasMany('dream_symbol', { embedded: 'always' })
serialize: ->
@getProperties [ 'guid', 'image', 'name', 'description', 'parents', 'children', 'siblings' ]
class DreamSymbolSerializer < ActiveModel::Serializer
attributes :id,
:name,
:description,
:user_id,
:image,
:parents,
:children,
:siblings
def parents
object.ancestor_ids if !object.is_root?
end
def children
object.descendant_ids if object.has_children?
end
def siblings
object.sibling_ids if object.has_siblings?
end
end
def show
@dream_symbol = DreamSymbol.find( params[:id] )
respond_with @dream_symbol, meta: { children: @dream_symbol.children, parents: @dream_symbol.ancestors, siblings: @dream_symbol.siblings }, meta_key: nil
end
%h1
= hb 'name'
%small
%btn.btn.btn-default.btn-xls{ _action: 'edit' }
%i.fa.fa-pencil
%p= hb 'description'
= hb 'each sibling in siblings' do
= hb 'sibling.name'
Woot
{"dream_symbol":{"id":1,"name":"Red","description":"xxx in the colour spectrum.","user_id":null,"image":"","parents":[3],"children":null,"siblings":[9,1]},"meta":{"children":[],"parents":[{"id":3,"name":"Colour","ancestry":"","description":"Various spectrums of light create all colours.","user_id":null,"image":"","created_at":"2014-04-03T04:26:13.446Z","updated_at":"2014-04-03T16:23:40.865Z"}],"siblings":[{"id":9,"name":"Blue","ancestry":"3","description":"ttttt","user_id":null,"image":null,"created_at":"2014-04-03T14:27:28.743Z","updated_at":"2014-04-06T15:16:30.388Z"},{"id":1,"name":"Red","ancestry":"3","description":"xxx in the colour spectrum.","user_id":null,"image":"","created_at":"2014-03-03T02:26:32.672Z","updated_at":"2014-04-05T00:04:44.909Z"}]}}
@bj-mcduck
Copy link
Author

Found this article:
http://www.kaspertidemann.com/representing-objects-in-ember-data/

That's supposed to allow for embedded objects but that errors out.

So does the normal DS.hasMany() object.
I get the same error in both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment