console - Rails deleting record in join table -
i have 2 associated tables, 'releases' & 'tracks' contain fields 'name' , 'isrc' respectively.
i trying remove tracks database when release.name equal value, e.g "thriller".
the relationship here 'track' belongs_to 'release' , 'release' has_many 'tracks'.
can me how achieve within rails console?
in release model:
has_many :tracks, dependent: :destroy
this remove tracks associated release database when destroy release.
you can test doing in console
release = realse.where(name:"thriller").first release_id = release.id release.destroy tracks = track.where(release_id:release_id)
the variable tracks should empty.
Comments
Post a Comment