class Article < ActiveRecord::Base
has_many :pages
end
class Page < ActiveRecord::Base
belongs_to :article
end
Check if the association exist by:
Article.reflect_on_association(:pages)
or
Page.reflect_on_association(:article)
If the association not exist, the return value of Page.reflect_on_association(:article)
will be nil
, otherwise it puts like :
#<ActiveRecord::Reflection::HasManyReflection:0x00007fbe099d9c10
@active_record=
Page(id: integer, name: string),
@association_scope_cache={},
@automatic_inverse_of=false,
@constructable=true,
@foreign_type="article_type",
@klass=nil,
@name=:article,
@options={:autosave=>true},
@plural_name="articles",
@scope=nil,
@scope_lock=#<Thread::Mutex:0x00007fbe099d9990>,
@type=nil>
It mains the association exist,and you can get more info about it.