Include foreign object

8 views
Skip to first unread message

David Sherratt

unread,
Jan 6, 2014, 1:48:54 PM1/6/14
to roar...@googlegroups.com
Hi,
I have a ticket system and want to include the author of a ticket with the json object
Collection does not work due to it being a singular relationship



module TicketRepresenter
  include Roar::Representer::JSON
  
  property :title  
  property :user_id

  collection :collect, :extend => AuthorRepresenter, :from => :user
end


How else can I include the user table?

model is

class Ticket < ActiveRecord::Base
  belongs_to :user
end

class User < ActiveRecord::Base
   has_many :tickets
end


Thanks
Dave

David Sherratt

unread,
Jan 6, 2014, 1:57:17 PM1/6/14
to roar...@googlegroups.com
Solved by this approach :


module TicketRepresenter
  include Roar::Representer::JSON
  
  property :id  
  property :title  
  property :content 
  property :user_id

  property :user, :extend => AuthorRepresenter, :class => User
end

Nick Sutterer

unread,
Jan 6, 2014, 4:35:00 PM1/6/14
to roar...@googlegroups.com
Doesn't the README say that? Maybe I should add a note. Thanks


--
You received this message because you are subscribed to the Google Groups "Roar" group.
To unsubscribe from this group and stop receiving emails from it, send an email to roar-talk+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages