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?
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
test output