[OT] ROR Difference between has one and belongs to one

Mark Wieder mwieder at ahsoftware.net
Wed Apr 25 22:19:17 EDT 2012


Bob-

Tuesday, April 24, 2012, 9:31:05 AM, you wrote:

> Hi. For anyone who has experience using Ruby on Rails, I have a
> friend who is redesigning the corporate web site, and he wants to
> use ROR. He is stumped at their way of defining relationships. He
> says there is a Belongs To One relationship and a Has One
> relationship. It sounds to me like they are talking about a one to
> one relationship from different directions but why that would be
> useful I do not know. Anyone have any wisdom on the subject?

Typically in object-oriented design you're presented with the choice
between subclassing an existing object (making a new object with all
the properties of the original, but with a few additions or
differences) or creating an aggregate object which contains two or
more other objects. The textbook answer to when you do one and when
you do the other comes down to:

if you have a "has a" relationship then you make a complex object
if you have a "is a" relationship then you subclass an existing one

For instance, if you want to create a button with a blue background,
you'd use a button object and change its properties. That would be an
"is a" relationship. You wouldn't make a group with a button and a
blue graphic overlay object to do the trick.

Rails also has the concept of "convention over configuration", which
is basically "we've already figured out the best way to do things, so
don't get creative here." The idea being that if you have to go and
configure things they'll break, so just use the frameworks the way
they're written, and design your application around rails rather than
trying to integrate rails into your application.

-- 
-Mark Wieder
 mwieder at ahsoftware.net





More information about the use-livecode mailing list