class SqlSkelton::Fkey

class SqlSkelton::Fkey

Summary

Class for mapping a foreign key relation

Description

Three methods only. To access it, via child or parent.

Attributes

child[R]

Access the child via

fkey.child[:tbl]  # => Child table name
fkey.child[:col]  # => Child column name
parent[R]

Access the parent via

fkey.parent[:tbl]  # => Parent table name
fkey.parent[:col]  # => Parent column name

Public Class Methods

new(tbl_child, col_child, tbl_parent, col_parent) click to toggle source

Set up the basic parameters.

@param tbl_child [String] Table referenced to @param col_child [String] Column referenced to @param tbl_parent [String] Table referenced from @param col_parent [String] Column referenced from

# File lib/db_suit_rails/sql_skelton/fkey.rb, line 40
def initialize(tbl_child, col_child, tbl_parent, col_parent)
  tbl_child  = remove_sqlprefix(tbl_child)
  tbl_parent = remove_sqlprefix(tbl_parent)
  @child  = { :tbl => tbl_child,  :col => col_child }
  @parent = { :tbl => tbl_parent, :col => col_parent } 
  if !(@child[:tbl] && @child[:col] && @parent[:tbl] && @parent[:col])
    msg = sprintf('child(tbl|col) = (%s | %s)  parent(tbl|col) = (%s | %s)', @child[:tbl].inspect, @child[:col].inspect, @parent[:tbl].inspect, @parent[:col].inspect)
    raise DbSuitRailsFkeyError, 'None of the table/column should be nil.: '+msg
  end
end

Public Instance Methods

==(obj) click to toggle source

Equality implementation

# File lib/db_suit_rails/sql_skelton/fkey.rb, line 53
def ==(obj)
  begin
    (@child == obj.child) && (@parent == obj.parent)
  rescue
    false
  end 
end