From 810f2a65c36a0a9def8e01524b996dcf9969aa52 Mon Sep 17 00:00:00 2001 From: Sandip Mane Date: Sat, 27 Jun 2020 14:16:35 +0530 Subject: [PATCH] Added docs for habtm association about the declaring model referring to zero or more associations parent f4471fc728d372861095d8f0a5b19831e316ead7 author Sandip Mane 1593247595 +0530 committer Sandip Mane 1597253412 +0530 Adds doc for habtm association for always optional: true Added docs line under definition of habtm with a text containing habtm refers to zero or more associations Added docs line under definition of habtm with a text containing it refers to zero or more associations Updated the sentence to include declaring association for habtm relation --- guides/source/association_basics.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/guides/source/association_basics.md b/guides/source/association_basics.md index 08b2743cc3..14f388730c 100644 --- a/guides/source/association_basics.md +++ b/guides/source/association_basics.md @@ -118,7 +118,7 @@ end ``` When used alone, `belongs_to` produces a one-directional one-to-one connection. Therefore each book in the above example "knows" its author, but the authors don't know about their books. -To setup a [bi-directional association](#bi-directional-associations) - use `belongs_to` in combination with a `has_one` or `has_many` on the other model. +To setup a [bi-directional association](#bi-directional-associations) - use `belongs_to` in combination with a `has_one` or `has_many` on the other model. `belongs_to` does not ensure reference consistency, so depending on the use case, you might also need to add a database-level foreign key constraint on the reference column, like this: @@ -356,7 +356,9 @@ end ### The `has_and_belongs_to_many` Association -A `has_and_belongs_to_many` association creates a direct many-to-many connection with another model, with no intervening model. For example, if your application includes assemblies and parts, with each assembly having many parts and each part appearing in many assemblies, you could declare the models this way: +A `has_and_belongs_to_many` association creates a direct many-to-many connection with another model, with no intervening model. +This association indicates that each instance of the declaring model refers to zero or more instances of another model. +For example, if your application includes assemblies and parts, with each assembly having many parts and each part appearing in many assemblies, you could declare the models this way: ```ruby class Assembly < ApplicationRecord -- GitLab