flatiron / resourceful

an isomorphic Resource engine for JavaScript
http://github.com/flatiron/resourceful
Apache License 2.0
354 stars 56 forks source link

Hierarchy relationships misnomer? #31

Closed coreyjewett closed 12 years ago

coreyjewett commented 12 years ago

Was just reading wiki on Hierarchy relationships. Cool.

I object to the method name #parent(). It is not accurately descriptive of the relation. In the Shakespeare example given the method should be #belongs_to (keep reading, this isn't right either). As in:

Book = resourceful.define('book', function () {
  this.property('title');
  this.belongs_to('Author');
});

There is a #has_many implicit in the current implementation that perhaps should be explicit:

Author = resourceful.define('author', function () {
  this.property('name');
  this.has_many(Book);
});

Finally, since I'm picking on this example, I'm not sure #belongs_to is appropriate because a book can have multiple Authors.

I think this feature should be pulled (or at least renamed from #parent to #has_many) until some of the magic is stripped out and it follows relation modeling and terminology. Ruby on Rails' ActiveRecord might be a good case study for this.

jfhbrook commented 12 years ago

I think this feature should be pulled

No.

I object to the method name #parent(). It is not accurately descriptive of the relation.

Yeah, but javascript isn't English either. I think "parent" is somewhat appropriate because you're specifying the parent of your node (now a child).

If I were to suggest a namechange, I'd go with this.childOf('Author').

coreyjewett commented 12 years ago

I would be agreeable to childOf I never liked belongs_to.

My suggestion for pulling the feature was in the context of #childOf modeling only one variety of relationship. At least with a renaming we're reducing the need for future API changes if this fleshes out more.

yes?

indexzero commented 12 years ago

has_many, belongs_to { thru: 'some-model' } and more complex relational algebra isn't going to be implemented across the board.

Implementing only parent, child, all and find is enough to get by anywhere. If you're using something more SQL like, the engine should extend the Resource prototype with whatever methods necessary.