Note that there are some explanatory texts on larger screens.

plurals
  1. POActiveScaffold::ReverseAssociationRequired error for new record creation
    text
    copied!<p>I have three models :</p> <pre><code>class LevelTwoArea &lt; ActiveRecord::Base has_many :places, dependent: :restrict end class Place &lt; ActiveRecord::Base belongs_to :level_two_area has_many :producers, dependent: :restrict validates_presence_of :level_two_area_id end class Producer &lt; ActiveRecord::Base belongs_to :place validates_presence_of :place_id end </code></pre> <p>I also have a controller with an ActiveScaffold per model. </p> <p><strong>Problem is, when i want to create a new <code>Place</code>, the scaffold spits an error to the log :</strong> </p> <pre><code>ActiveScaffold::ReverseAssociationRequired (Association producers: In order to support :has_one and :has_many where the parent record is new and the child record(s) validate the presence of the parent, ActiveScaffold requires the reverse association (the belongs_to).) </code></pre> <p>I don't understand why...</p> <p>Notice that : </p> <ul> <li>Other similar scaffolds do work</li> <li><p>i can create records and use associations in the console :</p> <pre><code>&gt;&gt; Place.new name: 'PONVOGO', level_two_area_id: 10144 =&gt; #&lt;Place id: nil, name: "PONVOGO", latitude: nil, longitude: nil, producers_count: nil, level_two_area_id: 10144, created_at: nil, updated_at: nil, marker: nil&gt; &gt;&gt; _.save =&gt; true &gt;&gt; Producer.first.place.producers =&gt; [#&lt;Producer id: 1, name: "KOFFI YAO GREGOIRE", place_id: 43, created_at: nil, updated_at: nil&gt;] </code></pre></li> <li><p>The problem disappears when i remove the <code>has_many :producers</code>, though the association macros look perfectly normal</p></li> <li>The problem won't disappear if i remove the <code>dependent: :restrict</code> option</li> <li>i have a <code>producers_census</code> column on my <code>Place</code> model, i suspect this to mess things up but would like to have confirmation before doing heavy refactoring. Removing this column from the scaffold won't fix the problem.</li> </ul> <p>fields on the <code>places</code> table : </p> <pre><code>Column | Type | -------------------------------------------------- id | integer | non NULL (PK) name | character varying(50) | non NULL latitude | double precision | longitude | double precision | producers_census | integer | level_two_area_id | integer | non NULL (FK) created_at | timestamp without time zone | updated_at | timestamp without time zone | marker | geometry | </code></pre> <p>my entire <code>PlacesController</code> :</p> <pre><code>class PlacesController &lt; ApplicationController active_scaffold :place do |conf| conf.columns = :name, :level_two_area, :latitude, :longitude, :producers_census export.columns.add :id, :level_two_area_id [:latitude, :longitude].each {|column| conf.columns[column].options[:format] = "%.14f" } [ create, update, delete, batch_update ].each do |action| action.link.security_method = :can_see_link? end batch_destroy.link.each {|sublink| sublink.security_method = :can_see_link? } end end </code></pre> <p>i'm on rails (3.0.5) / active_scaffold_vho (3.0.17) / ruby (1.9.2p180)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload