method
foreign_keys
v7.1.3.4 -
Show latest stable
-
0 notes -
Class: ActiveRecord::ConnectionAdapters::SQLite3Adapter
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0
- 3.0.9
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7 (0)
- 5.2.3 (0)
- 6.0.0 (0)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (0)
- 7.1.3.4 (0)
- What's this?
foreign_keys(table_name)
public
Hide source
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 368 def foreign_keys(table_name) # SQLite returns 1 row for each column of composite foreign keys. fk_info = internal_exec_query("PRAGMA foreign_key_list(#{quote(table_name)})", "SCHEMA") grouped_fk = fk_info.group_by { |row| row["id"] }.values.each { |group| group.sort_by! { |row| row["seq"] } } grouped_fk.map do |group| row = group.first options = { on_delete: extract_foreign_key_action(row["on_delete"]), on_update: extract_foreign_key_action(row["on_update"]) } if group.one? options[:column] = row["from"] options[:primary_key] = row["to"] else options[:column] = group.map { |row| row["from"] } options[:primary_key] = group.map { |row| row["to"] } end ForeignKeyDefinition.new(table_name, row["table"], options) end end