I have a model Userthat looks like this:
User
class User < ApplicationRecord belongs_to :organization belongs_to :department end
The table usersin the database has two foreign keys organization_idand department_id. How can I make these two columns a composite primary key? So far I have seen two approaches:
users
organization_id
department_id
Use composite_primary_keysgem
composite_primary_keys
Add an index to each of the two columns using something like this:
add_index :users, [:organization_id, :department_id], unique: true
What is the best way to uniquely identify rows in a table users, where the line should be department_idand organization_idto uniquely identify? What is the difference between indexing both columns and just turning each column into the primary key of the table?
Thank!
.
, id .
id
... , , , , , t... BTW, , , Rails... , - . - , id , . . , , ...
, id , , organisation_id + department_id...
organisation_id
. , / - , , ... , .:) ... , Rails , , ... PITA, .
... - . , org_id/dept_id ... , ... db, ...
(OTOH) , ... , - , 42 23 . , , db.
Source: https://habr.com/ru/post/1667949/More articles:Creating a transition when changing properties in angular 2/4 - angularLoopbackjs: DB switch in data source based on query source - javascriptWhat happens if you do not bet 1; at the end of the package? - perlHow to create and populate pandas dataframe from for loop? - pythonLoading JSON data into a table does not work - jsonWhat it means is that the signature of the index of the type of an object is implicitly of the type "any."FCM error message: InvalidParameters - androidC # filter elements in a list according to several criteria - listSyntaxError: Unexpected token \ in JSON in position - jsonHow to debug nopCommerce plugin during development? - c #All Articles