Last active
December 27, 2015 17:18
-
-
Save laspluviosillas/7360700 to your computer and use it in GitHub Desktop.
Interview Question #3
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
class Author < ActiveRecord::Base | |
attr_accessible :name, :admin # :name => string, :admin => boolean | |
has_many :posts | |
end | |
class Post < ActiveRecord::Base | |
attr_accessible :name, :description # :author_id => int, :name => string, :description => string | |
belongs_to :author | |
has_many :comments | |
end | |
class Comment < ActiveRecord::Base | |
attr_accessible :description # :post_id => int, :description => string | |
belongs_to :post | |
end | |
# Structure example: | |
# Author -- name: James Strong, admin: true | |
# Post -- name: "I like Ruby", description "Ruby on Rails is great!" | |
# Comment -- description: "This is a good post" | |
# => Search all the Comments that have an Author (through the Post relationship) that is an administrator. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment