self-referential

How to prevent deep recursive queries with entities consisting of entities of the same type? [Cool example inside]

No worries! It looks more complex than it actually is! Just get down to the drinks! TLDR-version: How to efficiently query and update entities having relationships to other entities? Here's an interesting data modeling scenario with two tables that has been puzzling me: Entities { ID, Name, ScalarValue } ComponentEntities { Aggregate...

How do I implement a 'social' aspect with mongoid

I am attempting to create a friend network on a site I am making. I am using Mongoid. How do I instantiate friends? I assume that Users needs to have a relational association with multiple other users. But the following code: class User include Mongoid::Document references_many :users, :stored_as=>:array, :inverse_of=> :users en...

Self referential table and recursive SQL function

Hi All, I have a category table with: categoryID parentCategoryID categoryName and an items table with: itemID categoryID itemName I am using MySQL. i want to write a query that will return a count of Items in a category given a categoryID. The query should return total count for all items in all subcategories of the given categ...