29
Gibt es eine Möglichkeit herauszufinden, welche Assoziationen ein Modell hat? Nehmen Sie diese zwei Modelle:rails-Methode, um den Assoziationsnamen eines Modells zu erhalten
class Comment < ActiveRecord::Base
belongs_to :commentable
end
class Post < ActiveRecord::Base
has_many :comments
belongs_to :user
end
Ich bin auf der Suche nach so etwas wie:
Post.has_many #=> ['comments', ...]
Post.belongs_to # => ['user']
Comment.belongs_to # => ['commentable']
Perfekt! Vielen Dank. – DiegoSalazar