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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:25:22+00:00 2026-05-25T19:25:22+00:00

class Account include Mongoid::Document include Geocoder::Model::Mongoid geocoded_by :zip devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable,

  • 0
class Account
  include Mongoid::Document
  include Geocoder::Model::Mongoid
  geocoded_by :zip
  devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable

  before_validation :pass_confirm
  after_validation :geocode_check
  before_create :assign_subs

  field :email, type: String
  field :type, type: String
  field :zip, type: String
  field :oldzip, type: String
  field :coordinates, type: Array
  field :latitude, type: Float
  field :longitude, type: Float
  auto_increment :num, collection: :account_nums

  index :num, unique: true

  has_many :submissions

  mount_uploader :photo, PhotoUploader

  def self.find_by_num(num)
    Account.where(num: num).first
  end

  protected

  def pass_confirm
    self.password_confirmation ||= self.password
  end

  def geocode_check
    if self.oldzip != self.zip
      self.oldzip = self.zip
      self.geocode
    end
  end

  def assign_subs
    binding.pry
    Submission.where(email: self.email).each do |sub|
      sub.zip = self.zip
      self.submissions << sub
    end
  end

end

—

class Submission
  include Mongoid::Document
  include Mongoid::Search
  include Mongoid::Timestamps::Created
  include Geocoder::Model::Mongoid
  geocoded_by :zip

  before_validation :fix_rate
  after_validation :geocode

  search_in :message, tags: :name

  field :email, type: String
  field :rate, type: String
  field :message, type: String
  field :type, type: String
  field :zip, type: String
  field :coordinates, type: Array
  field :latitude, type: Float
  field :longitude, type: Float
  auto_increment :num, collection: :submission_nums

  index :num, unique: true

  has_and_belongs_to_many :tags
  belongs_to :account

  mount_uploader :photo, PhotoUploader

  protected

  def fix_rate
    self.rate = self.rate.sub(/[^\d]*/, '').sub(/(\d*).*/, '\1')
  end

end

—

pry(#<Account>)> self.submissions << Submission.first
=> [#<Submission _id: 4e751df86066252059000054, _type: nil, created_at: 2011-09-17 22:23:52 UTC, _keywords: ["tfnwuaty"], email: "krisbltn@gmail.com", rate: "49", message: "tfnwuaty", type: "person", zip: nil, coordinates: nil, latitude: nil, longitude: nil, num: 1, tag_ids: [], account_id: BSON::ObjectId('4e751e0d6066252059000059'), photo: "lawrence.jpg">]
pry(#<Account>)> self.submissions
=> []

as you see above, when trying to add a child document it doesn’t get saved. Any ideas as to what could be going on?

Also- this is a has_many / belongs_to relationship, and when I change it to has_and_belongs_to_many it seems to work fine.

  • 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-25T19:25:23+00:00Added an answer on May 25, 2026 at 7:25 pm

    My guess is that you’ve upgraded Mongoid, but haven’t read the upgrading docs.

    Add , :autosave => true to Account’s relation with Submission.

    class Account
      include Mongoid::Document
      has_many :submissions, :autosave => true
    end
    
    class Submission
      include Mongoid::Document
      belongs_to :account
    end
    
    Account.delete_all
    Submission.delete_all
    
    Submission.create
    account = Account.new
    account.submissions << Submission.first
    account.save
    Submission.first.account == account
    

    This was also submitted as a GitHub issue. Tsk tsk.

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

Sidebar

Related Questions

With include('basemodel.php'); I get Fatal error: Class 'BaseModel' not found in C:\xampp\htdocs\allsides\account\model.php on line
I have a View class (OrderView.aspx) which shows the details of an order (Account
class Tag(models.Model): name = models.CharField(maxlength=100) class Blog(models.Model): name = models.CharField(maxlength=100) tags = models.ManyToManyField(Tag) Simple
class Foo(models.Model): title = models.CharField(max_length=20) slug = models.SlugField() Is there a built-in way to
I have this snippet of the code account.cpp #include account.h #include <iostream> #include <string>
class Foo { static bool Bar(Stream^ stream); }; class FooWrapper { bool Bar(LPCWSTR szUnicodeString)
class A : IFoo { } ... A[] arrayOfA = new A[10]; if(arrayOfA is
class someclass {}; class base { int a; int *pint; someclass objsomeclass; someclass* psomeclass;
class AbstractQuery { virtual bool isCanBeExecuted()=0; public: AbstractQuery() {} virtual bool Execute()=0; }; class
class C { T a; public: C(T a): a(a) {;} }; Is it legal?

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.