class Article < ActiveRecord::Base has_many :comments belongs_to :category end
Is there a class method for Article with which I can retrieve a list of associations? I know by looking at the model's code that Article is associated to Comment and Category. But is there a method to get these associations programmatically?
List of modeling agencies around the world in alphabetical order: Avenue 1 Co. Ltd. Cameron's Management Pty Ltd. Deco Models Inc. GO! Models M Inc. Nova Ltd. Prime Agency Co. Ltd. Select Model Management Ltd. Team Inc.
The sample data provided with ArcFM Solution makes extensive use of model names. These model names are divided into two required domains: the Field Model Name Domain and the Object Class Model Name Domain.
This model name is also critical to tracing, Conduit Manager, and reporting. Some examples of connectable objects include Fiber, BacksidePort, FrontsidePort, DevicePort, SplitterInputPort, and SplitterOutputPort. Any object that should be connectable in the Connection Manager.
In ArcFM Solution Desktop: This model name must be assigned to pipe feature classes that participate in cathodic protection systems. If this model name is assigned to ArcFM System Tables, all tabs in the Properties Manager will be displayed. By default only the Model Names and Field Model Names tabs are displayed for System Tables.
You want ActiveRecord::Reflection::ClassMethods#reflect_on_all_associations
So it would be:
Article.reflect_on_all_associations
And you can pass in an optional parameter to narrow the search down, so:
Article.reflect_on_all_associations(:has_many) Article.reflect_on_all_associations(:belongs_to)
Keep in mind that if you want the list of all the names of the models you can do something like:
Article.reflect_on_all_associations(:belongs_to).map(&:name)
This will return a list of all the model names that belong to Article
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With