Created
July 22, 2009 19:44
-
-
Save itspriddle/152219 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| mysql> describe contacts; | |
| +------------+---------------------+------+-----+---------+----------------+ | |
| | Field | Type | Null | Key | Default | Extra | | |
| +------------+---------------------+------+-----+---------+----------------+ | |
| | id | bigint(20) unsigned | NO | PRI | NULL | auto_increment | | |
| | user_id | bigint(20) unsigned | NO | | NULL | | | |
| | first_name | varchar(255) | YES | | NULL | | | |
| | last_name | varchar(255) | YES | | NULL | | | |
| | company | varchar(255) | YES | | NULL | | | |
| | address_1 | varchar(255) | YES | | NULL | | | |
| | address_2 | varchar(255) | YES | | NULL | | | |
| | city | varchar(255) | YES | | NULL | | | |
| | state | char(2) | YES | | NULL | | | |
| | zip | tinyint(5) unsigned | YES | | NULL | | | |
| | home_phone | bigint(11) unsigned | YES | MUL | NULL | | | |
| | cell_phone | bigint(11) unsigned | YES | MUL | NULL | | | |
| | created_at | datetime | YES | | NULL | | | |
| | updated_at | datetime | YES | | NULL | | | |
| +------------+---------------------+------+-----+---------+----------------+ | |
| 14 rows in set (0.01 sec) | |
| mysql> describe contact_groups; | |
| +------------+---------------------+------+-----+---------+----------------+ | |
| | Field | Type | Null | Key | Default | Extra | | |
| +------------+---------------------+------+-----+---------+----------------+ | |
| | id | bigint(20) unsigned | NO | PRI | NULL | auto_increment | | |
| | user_id | bigint(20) unsigned | NO | MUL | NULL | | | |
| | name | varchar(255) | NO | | NULL | | | |
| | created_at | datetime | YES | | NULL | | | |
| | updated_at | datetime | YES | | NULL | | | |
| +------------+---------------------+------+-----+---------+----------------+ | |
| 5 rows in set (0.00 sec) | |
| mysql> describe contact_group_members; | |
| +------------------+---------------------+------+-----+---------+----------------+ | |
| | Field | Type | Null | Key | Default | Extra | | |
| +------------------+---------------------+------+-----+---------+----------------+ | |
| | id | bigint(20) unsigned | NO | PRI | NULL | auto_increment | | |
| | contact_id | bigint(20) unsigned | NO | MUL | NULL | | | |
| | contact_group_id | bigint(20) unsigned | NO | | NULL | | | |
| +------------------+---------------------+------+-----+---------+----------------+ | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class User < ActiveRecord::Base | |
| has_many :contacts | |
| has_many :contact_groups | |
| end | |
| class Contact < ActiveRecord::Base | |
| belongs_to :user | |
| has_many :contact_group_members | |
| has_many :contact_groups, :through => :contact_group_members | |
| end | |
| class ContactGroup < ActiveRecord::Base | |
| belongs_to :user | |
| has_many :contact_group_members | |
| has_many :contacts, :through => :contact_group_members | |
| end | |
| class ContactGroupMember < ActiveRecord::Base | |
| belongs_to :contacts | |
| belongs_to :contact_groups | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment