Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here'a how to get association metadata.</p> <p>Mongoid::Relations::Reflections#reflect_on_all_associations - see <a href="http://rdoc.info/github/mongoid/mongoid/Mongoid/Relations/Reflections" rel="nofollow">http://rdoc.info/github/mongoid/mongoid/Mongoid/Relations/Reflections</a></p> <p>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.</p> <p>The following is for "the old API," so you should use the above instead.</p> <p>Mongoid::Relations::ClassMethods::associations - see <a href="http://rdoc.info/github/mongoid/mongoid/Mongoid/Relations/ClassMethods:associations" rel="nofollow">http://rdoc.info/github/mongoid/mongoid/Mongoid/Relations/ClassMethods:associations</a></p> <p>test/unit/cali_test.rb</p> <pre><code>require 'test_helper' class CaliTest &lt; 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 </code></pre> <p>test output</p> <pre><code>Run options: --name=test_mongoid_fields # Running tests: Cali.reflect_on_all_associations(*macros):[#&lt;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&gt; ] Address.reflect_on_all_associations(*macros):[#&lt;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&gt; ] . Finished tests in 0.008605s, 116.2115 tests/s, 116.2115 assertions/s. 1 tests, 1 assertions, 0 failures, 0 errors, 0 skips </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload