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

  • Home
  • SEARCH
  • 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 8659081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:55:12+00:00 2026-06-12T15:55:12+00:00

I have a self-referencing loop that references the most recent associated record to see

  • 0

I have a self-referencing loop that references the most recent associated record to see if it’s caught up. However, it keeps referencing the first associated record, so it keeps going in an infinite loop. I think this is because the ActiveRecord transaction keeps running throughout the loop, so it never stops and updates itself.

Is there any way to force a model to reset itself before continuing on?

Here’s my model (not that the exception raising is just so I can verify whether we’ve actually advanced to the next record).

class RecurringRule < ActiveRecord::Base
  belongs_to :organization
  has_one :last_run, :class_name => "Transaction", :order => 'id DESC'
  has_many :transactions

  attr_accessible :period, :last_run_id

  after_create :destroy_if_period_empty

  def destroy_if_period_empty
    if !period?
      self.destroy
    end
  end

  def recur
    @count = @count || 0
    if @count > 0 then raise last_run.id.to_s end
    if last_run.created_at.to_date.advance(period.pluralize.to_sym => 1) >= Date.today 
      new = Transaction.new({
        amount: last_run.amount,
        person_id: last_run.person_id,
        organization_id: last_run.organization_id,
        recurring_rule_id: last_run.recurring_rule_id
      })
      new.save!
      @count += 1
      self.recur
    end
    return @count
  end
end
  • 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-06-12T15:55:13+00:00Added an answer on June 12, 2026 at 3:55 pm

    You can try

    Model.association(force_reload=true)
    

    See here for reference (it is valid also for has many relations)

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

Sidebar

Related Questions

I have a self referencing table named categories that has a parentcategoryid column that
I have a self referencing table in Oracle 9i, and a view that gets
I have a table that has an Self referencing relationship - One Wall comment
I have a self-referencing table (Customers) and a table that will link to one
I have a self-referencing many-to-many relationship between users and managers that looks like this:
I have a self-referencing table 'comments' where comments.replyToId REFERENCES comments.ID. My question is, how
I am trying to learn Self Referencing Forms . I have read that a
I have a self referencing table and I want a mysql query that will
I have a table in my source DB that is self referencing |BusinessID|...|ParentID| This
I have a table called Metrics that is a self-referencing table. Meaning it has

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.