开发者

Rails 3: Dependent => :deny or similar?

开发者 https://www.devze.com 2023-03-05 07:53 出处:网络
I have a model \"location\", which has many \"courses\" If I destroy a location, I\'d like the destroy request to be rejected unless there are no relationships between the location and any courses. I

I have a model "location", which has many "courses"

If I destroy a location, I'd like the destroy request to be rejected unless there are no relationships between the location and any courses. I assume there's some pretty concise way of doing this, but I can't fin开发者_如何学Cd anything.

Soo...what's the most elegant/simple/concise way of enabling this sort of functionality?


in Location...

before_destroy do |l|
  return false unless l.courses.nil?
end 
0

精彩评论

暂无评论...
验证码 换一张
取 消