开发者

what are dependencies in rails/ruby

I am a beginner is rails, every now and then I come across dependencies. I tried to figure out what it means, but was not abl开发者_StackOverflowe to. Can someone please explain me what it means?


Hm, if you are talking about the :dependent option for describing a has_one relationship, you use that option to change the default behavior for what happens to a child row when a row in the parent table gets deleted.

:dependent => :destroy

Child row is destroyed when parent row is destroyed.

:dependent => :nullify

Child row's foreign key is set to null (it is orphaned).

:dependent => :delete

When parent is destroyed the child row is deleted without calling its destroy method.

You can also use these to change the behavior of a has_many relationship, except they will apply to every child row, and you would use :delete_all instead of :delete.

A "dependency" in the general sense of the word means that a table is being used by another table - thus one table "depends" on another.


Say you install a gem in rails and if it in turn installs other gems then those gems are its dependencies.

As far as the answer above goes, you can accomplish the same using validates_uniqueness_of plugin.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜