Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7431703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:20:14+00:00 2026-05-29T09:20:14+00:00

I have three models : class LevelTwoArea < ActiveRecord::Base has_many :places, dependent: :restrict end

  • 0

I have three models :

class LevelTwoArea < ActiveRecord::Base
  has_many :places, dependent: :restrict
end

class Place < ActiveRecord::Base
  belongs_to :level_two_area
  has_many   :producers, dependent: :restrict

  validates_presence_of :level_two_area_id
end

class Producer < ActiveRecord::Base
  belongs_to :place

  validates_presence_of :place_id
end

I also have a controller with an ActiveScaffold per model.

Problem is, when i want to create a new Place, the scaffold spits an error to the log :

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).)

I don’t understand why…

Notice that :

  • Other similar scaffolds do work
  • i can create records and use associations in the console :

    >> Place.new name: 'PONVOGO', level_two_area_id: 10144
    => #<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>
    >> _.save
    => true
    >> Producer.first.place.producers
    => [#<Producer id: 1, name: "KOFFI YAO GREGOIRE", place_id: 43, created_at: nil, updated_at: nil>]
    
  • The problem disappears when i remove the has_many :producers, though the association macros look perfectly normal

  • The problem won’t disappear if i remove the dependent: :restrict option
  • i have a producers_census column on my Place 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.

fields on the places table :

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                    | 

my entire PlacesController :

class PlacesController < 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 

i’m on rails (3.0.5) / active_scaffold_vho (3.0.17) / ruby (1.9.2p180)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:20:15+00:00Added an answer on May 29, 2026 at 9:20 am

    While I’ve never seen this ActiveScaffold exception before, I think this is what’s going on:

    The reverse association is set up with the :inverse_of option, and its effects will be visible only while the records are unsaved. This is why you don’t see it in your console experiment.

    Try this:

    place = Place.new
    => #<Place ...>
    producer = place.producers.build
    => #<Producer ...>
    
    producer.place
    => nil
    place.producers.first.place
    => nil
    

    These records will fail your validation, when built entirely in memory. If you never build a place and a producer at the same time, then you don’t have to worry about this. If you do, however, then your validation rule also should be written to check for the existence of :place (i.e. the object), not :place_id:

    validates_presence_of :place
    

    I don’t know which build/creation mechanism ActiveScaffold uses, but I would guess that if they throw this exception, that they may build things in memory.

    So, to fix this, try:

    class Producer < ActiveRecord::Base
      belongs_to :place, inverse_of: producers
    
      validates_presence_of :place
    end
    
    class Place < ActiveRecord::Base
      has_many :producers, inverse_of: place
    end
    

    Note: ActiveRecord used to not support :inverse_of on the has_many side and that limitation used to be commented in the source. As of Rails 3.1, this seems fixed. If you amend your classes with :inverse_of as shown, then the console experiment with in-memory objects should return the associated object.

    You may want to review the Rails API docs on bi-directional associations

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three models: class Address < ActiveRecord::Base has_many :jobs end class Category <
Three models: class Customer < ActiveRecord::Base has_many :visits end class Visit < ActiveRecord::Base belongs_to
I have three models: class Tenant < ActiveRecord::Base has_many :sites end class Site <
I have a three models: class Feed < ActiveRecord::Base has_many :filters, :dependent => :destroy
I have three models defined as follows: class Comic < ActiveRecord::Base has_many :feeds end
I have three models: class ReleaseItem < ActiveRecord::Base has_many :pack_release_items has_one :pack, :through =>
I have three models: class Book < ActiveRecord::Base has_many :collections has_many :users, :through =>
I have three models that look something like this: class Bucket < ActiveRecord::Base has_many
I have three Models setup with the following associations class User < ActiveRecord::Base has_many
I have three models presented in a multi-model form. class Parent < ActiveRecord::Base has_many

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.