Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUBY

dependent destroy, only the foreign key

has_one :credit_card, dependent: :destroy  # destroys the associated credit card
has_one :credit_card, dependent: :nullify  # updates the associated records foreign
                                              # key value to NULL rather than destroying it
has_one :last_comment, -> { order('posted_on') }, class_name: "Comment"
has_one :project_manager, -> { where(role: 'project_manager') }, class_name: "Person"
has_one :attachment, as: :attachable
has_one :boss, -> { readonly }
has_one :club, through: :membership
has_one :primary_address, -> { where(primary: true) }, through: :addressables, source: :addressable
has_one :credit_card, required: true
Source by apidock.com #
 
PREVIOUS NEXT
Tagged: #dependent #foreign #key
ADD COMMENT
Topic
Name
5+8 =