Welcome to Giant Robots Smashing Into Other Giant Robots — a weblog about development, business, design and technology — written by thoughtbot.

not yet

Ok here’s an app as of right now.

All the app consists of are some forms for creating users, some forms for users to create comments, plus 1 additional page that displays each user and the total # of comments they have created. There is NO page that displays a comment and its user who created it.

The correct domain model based on the requirements right now is:

1
2
3
4
5
6
7
8
class User < ActiveRecord::Base

  has_many :comments

end

class Comment < ActiveRecord::Base
end

This association is unidirectional, it can only be traversed in one direction. There is no point in making this association bidirectional by adding a corresponding belongs_to :user in Comment. Adding that would be premature and a case of massive over-engineering. Since the association from Comment to User currently is not used in the app, adding it would just cause unnecessary complexity.

There is nothing wrong with unidirectional associations. Don’t make all associations bidirectional when its just not necessary; someday it might be but until then don’t do it.


About this entry

 

thoughtbot is hiring

We are hiring web developers and web designers in both Boston and New York, NY.

What are we up to?

We built Shoulda, an eclectic set of additions to Test::Unit; Paperclip to manage uploaded files without hassle; Jester, a REST/ActiveResource client library written in Javascript, and Squirrel, an enhancement for ActiveRecord's find syntax; — amongst some other projects.


Chad (President) and Jon (CTO) co-authored a technical book titled Pro Active Record: Databases with Ruby and Rails, which explores the ins and outs of the ActiveRecord ruby library. You can buy it today at Amazon.com.

About thoughtbot, inc.

We are a small web application development consulting business, with offices in Boston, MA and New York, NY. If you're looking to find a team for your next web development project or your new web application — get in touch.