activerecord-tableless icon indicating copy to clipboard operation
activerecord-tableless copied to clipboard

An example with nested attributes?

Open nathanvda opened this issue 11 years ago • 1 comments

Hi, I am the author of the cocoon gem, and received a request to be able to create nested forms with ActiveModel models. This gems seems like the perfect answer from the short explanation in the readme, except I have no idea how you can implement two nested tableless models.

In the code I see no overruling of any association code (at first sight), so not sure it is actually supported at all. Also, while claims are made, I see no examples ;)

If you can provide me with a simple explanation, I am willing to play around myself, no need for big elaborate examples ;) If I can get it to work, I can update the README myself :)

nathanvda avatar Jul 11 '14 13:07 nathanvda

On mt todo list I have an item syaing that I should demonstrate that in the cucumber tests...

However as it is now this feature is test in the specs: https://github.com/softace/activerecord-tableless/blob/master/spec/lib/activerecord-tableless_spec.rb

I know this is not the optimal source of information, but I may help you until I find some time to do it.

In my own project I have file models/integration/ejddb/order.rb

require 'activerecord-tableless'
class Integration::Ejddb::Order < ActiveRecord::Base
  has_no_table
  has_many :files, :class_name => 'Integration::Ejddb::File', :foreign_key => 'order_id', :validate => false

file models/integration/ejddb/file.rb

require 'activerecord-tableless'
class Integration::Ejddb::File < ActiveRecord::Base
  has_no_table
  belongs_to :order, :class_name => 'Integration::Ejddb::Order', :foreign_key => 'order_id';

jarl-dk avatar Jul 11 '14 13:07 jarl-dk