Skip to content

Commit dc1c679

Browse files
committed
Revert "Merge pull request rails#33385 from lanzhiheng/add-example-for-has-and-belongs-to-many-association"
This reverts commit 3c8c410, reversing changes made to daee94d. We have this information below in the reference section for has_and_belongs_to_many.
1 parent 5df23a0 commit dc1c679

File tree

1 file changed

+0
-16
lines changed

1 file changed

+0
-16
lines changed

guides/source/association_basics.md

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -365,22 +365,6 @@ class CreateAssembliesAndParts < ActiveRecord::Migration[5.0]
365365
end
366366
```
367367

368-
As you can see we don't create the relevant model for `assemblies_parts` table, So We can't create the many-to-many record like this
369-
370-
``` ruby
371-
AssemblyPart.create(assembly: @assembly, part: @part) # => NameError: uninitialized constant AssemblyPart
372-
```
373-
374-
If you want to create the relevant many-to-many record, you can use the below code
375-
376-
``` ruby
377-
@assembly.parts << @part
378-
# Or
379-
@part.assemblies << @assembly
380-
```
381-
382-
They are equivalent.
383-
384368
### Choosing Between `belongs_to` and `has_one`
385369

386370
If you want to set up a one-to-one relationship between two models, you'll need to add `belongs_to` to one, and `has_one` to the other. How do you know which is which?

0 commit comments

Comments
 (0)