Is there any way I can get a list of models that are in a special model rail?
For example:
class project & lt; ActiveRecord :: Base has_one: Status ... End class works & lt; ActiveRecord :: base has_one: status ... and class status & lt; ActiveRecord :: Base is_to: Project belongs_to: Task # This is where I want to enter an array of association class # names (instead of doing% {project work}} (can be used to check input) # If it remains open to fail, if I add new associations in the future, validates_inclusion_of: status_of ,: in = & gt; ? ... end
Hope it has some kind of meaning!
This lets you associate the models and other items given on the given model Model.reflections
The one describing the objects will give a hash. You want all the values in a hash, which are the reflection :: Association refinance
classes. This code should take you to the array that you should get:
association_names = [] model. Reflections.each {| Key, value | Association_name & lt; & Lt; Key if value.instance_of? (ActiveRecord :: Reflection :: AssociationReflection)}
Comments
Post a Comment