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 7028787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:27:15+00:00 2026-05-28T00:27:15+00:00

The following model works fine for reads, updates, and deletes but not for creating.

  • 0

The following model works fine for reads, updates, and deletes but not for creating.

class Space < ActiveRecord::Base
  has_many :space_prices, :dependent => :destroy
  accepts_nested_attributes_for :space_prices, :allow_destroy => true
  has_many :space_price_availabilities, through: :space_prices, :order => "day_of_week, begin_time", read_only: true
end

class SpacePrice < ActiveRecord::Base
  belongs_to :space
  has_many :space_price_availabilities, inverse_of: :space_price, :dependent => :destroy, :order => "day_of_week, begin_time"
  accepts_nested_attributes_for :space_price_availabilities, :allow_destroy => true
end

class SpacePriceAvailability < ActiveRecord::Base
  belongs_to :space_price
end

I know the workaround is to implement a Space.space_price_availabilities method. It is not sufficient to just always reference Space.space_prices.space_price_availabilities b/c I need the complete list flattened and sorted.

If I comment out the has_many :through in Space, I can create new Spaces fine. Then if I uncomment the has_many :through in Space, I can read them and update them fine. It’s only on create that I get the following exception.

ActiveRecord::HasManyThroughCantAssociateThroughHasOneOrManyReflection

Checking the logs, the right SQL is being generated and called, but then hits this exception and rolls it back.

Any ideas? I’d really like to know if I’m missing something fundamental about the rails associations. It looks pretty straight-forward to me. The model is essentially the same as the example in the API documentation.

  • 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-28T00:27:15+00:00Added an answer on May 28, 2026 at 12:27 am

    Add :autosave => false on

    has_many :space_price_availabilities, autosave: false, 
      inverse_of: :space_price, :dependent => :destroy, 
      :order => "day_of_week, begin_time", autosave: false
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following example works fine in Firefox and Opera, but not in ie8. However,
Following works fine in shell: >>> from django.contrib.auth.models import User >>> user=User.objects.get(pk=1) >>> user.first_name
I've the following condition in one of my model which works for mysql. with_scope
I have the following model: public class Contact { public Contact() { Name =
I have the following model: public class Tag { public int Id { get;
I've got the following model: public class Competitor { public virtual int CompetitorId {
I have the following Model pattern: public abstract class PARENTCLASS {...} public class CHILD_A_CLASS
Given the following model, I want to index the fields (sequence,stock) class QuoteModel(models.Model): quotedate
I have the following model structure: class Container(models.Model): pass class Generic(models.Model): name = models.CharacterField(unique=True)
I've got the following problem: My Flashlight app works fine on my Samsung Galaxy

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.