Answer the question
In order to leave comments, you need to log in
Organizing ActiveRecord links?
There are 3 models:
class Post < ActiveRecord::Base
belongs_to :user
has_many :likes, :dependent => :destroy
has_many :users, through: :likes
end
class Like < ActiveRecord::Base
belongs_to :user
belongs_to :post
end
class User < ActiveRecord::Base
has_many :posts, :dependent => :destroy
has_many :likes, :dependent => :destroy
has_many :posts, through: :likes
end
@user.posts
), the script returns an array of liked posts. The same is true when deleting a user - only the "likes" of the user are deleted, but not the records of this user themselves. Answer the question
In order to leave comments, you need to log in
The same is true when deleting a user - only the "likes" of the user are deleted, but not the entries themselves.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question