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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:41:37+00:00 2026-06-04T07:41:37+00:00

My models are: class Cali include Mongoid::Document field :license_expire_date, :type => String field :license_issue_date,

  • 0

My models are:

class Cali
  include Mongoid::Document
  field :license_expire_date, :type => String
  field :license_issue_date, :type => String
  embeds_one :address
end

class Address
  include Mongoid::Document
  field :state, :type => String
  field :city, :type => String
  embedded_in :cali, :inverse_of => :address
end

When I use @fields = Cali.fields.keys, I get only the two fields (expire_date, issue_date). I don’t get the address in the result. Is there a way that I could find what is embedded and the fields inside it?

  • 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-04T07:41:37+00:00Added an answer on June 4, 2026 at 7:41 am

    Here’a how to get association metadata.

    Mongoid::Relations::Reflections#reflect_on_all_associations – see http://rdoc.info/github/mongoid/mongoid/Mongoid/Relations/Reflections

    Note that if you want to supply more than one macro as an argument to reflect_on_all_associations as currently written, the macros have to be args.
    If you want to supply an array, it has to be splatted, e.g. *macros, as in the following test.

    The following is for “the old API,” so you should use the above instead.

    Mongoid::Relations::ClassMethods::associations – see http://rdoc.info/github/mongoid/mongoid/Mongoid/Relations/ClassMethods:associations

    test/unit/cali_test.rb

    require 'test_helper'
    
    class CaliTest < ActiveSupport::TestCase
      def setup
        Cali.delete_all
      end
    
      test "mongoid fields" do
        address = Address.new(state: 'NJ', city: 'New Providence')
        cali = Cali.create(address: address)
        assert_equal(1, Cali.count)
        macros = [:has_one, :has_many, :belongs_to, :has_and_belongs_to_many, :embeds_one, :embeds_many, :embedded_in]
        puts "Cali.reflect_on_all_associations(*macros):#{Cali.reflect_on_all_associations(*macros).inspect}"
        puts "Address.reflect_on_all_associations(*macros):#{Address.reflect_on_all_associations(*macros).inspect}"
        #puts "Old API - Cali.associations:#{Cali.associations}"
        #puts "Old API - Address.associations:#{Address.associations}"
      end
    end
    

    test output

    Run options: --name=test_mongoid_fields
    
    # Running tests:
    
    Cali.reflect_on_all_associations(*macros):[#<Mongoid::Relations::Metadata
    class_name:           Address,
    cyclic:               No,
    dependent:            None,
    inverse_of:           N/A,
    key:                  address,
    macro:                embeds_one,
    name:                 address,
    order:                nil,
    polymorphic:          No,
    relation:             Mongoid::Relations::Embedded::One,
    setter:               address=,
    versioned:            No>
    ]
    Address.reflect_on_all_associations(*macros):[#<Mongoid::Relations::Metadata
    class_name:           Cali,
    cyclic:               No,
    dependent:            None,
    inverse_of:           address,
    key:                  cali,
    macro:                embedded_in,
    name:                 cali,
    order:                nil,
    polymorphic:          No,
    relation:             Mongoid::Relations::Embedded::In,
    setter:               cali=,
    versioned:            No>
    ]
    .
    
    Finished tests in 0.008605s, 116.2115 tests/s, 116.2115 assertions/s.
    
    1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Models: class User include Mongoid::Document embeds_many :user_topics end class UserTopic include Mongoid::Document embedded_in :user
I have three models: class Address < ActiveRecord::Base has_many :jobs end class Category <
my models class Auction belongs_to :item belongs_to :user, :foreign_key => :current_winner_id has_many :auction_bids end
Two models: class Task < ActiveRecord::Base has_many :subtasks end class Subtask < ActiveRecord::Base belongs_to
I have the following models: class FieldEntryValue < ActiveRecord::Base belongs_to :field_entry end and class
Three models: class Customer < ActiveRecord::Base has_many :visits end class Visit < ActiveRecord::Base belongs_to
In models: class Getdata(models.Model): title = models.CharField(max_length=255) state = models.CharField(max_length=2, choices=STATE, default=0) name =
I have the following models: class Price < ActiveRecord::Base belongs_to :product end class Metric
I have three models : class LevelTwoArea < ActiveRecord::Base has_many :places, dependent: :restrict end
I have the following models: class Match < ActiveRecord::Base has_and_belongs_to_many :teams end And class

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.