Last active
August 29, 2015 14:17
-
-
Save benbabics/2c1573b3a4ac87eb1053 to your computer and use it in GitHub Desktop.
Rails API
This file contains 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
### | |
possible schema | |
### | |
User | |
has_many :posts | |
has_many :tools | |
has_many :products, through: :tools | |
Post | |
belongs_to :user | |
has_many :tools | |
has_many :products, through: :tools | |
Tool | |
has_many :users | |
has_many :posts | |
### | |
pseudo-code | |
### | |
user # => { id: 1, name: "Ben Babics" } | |
user.posts # => [{ id: 3, name: "How To Fix Leaky Pipes", user_id: 1 }] | |
user.products # => [{ id: 5, name: "Hammer", user_id: 1, post_id: 3 }] | |
user.posts.first # => { id: 3, name: "How To Fix Leaky Pipes", user_id: 1 } | |
user.posts.first.products # => [{ id: 5, name: "Hammer", user_id: 1, post_id: 3 }] | |
post.products # => [{ id: 5, name: "Hammer", user_id: 1, post_id: 3 }] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment