On Thu, Apr 24, 2008 at 8:59 PM, Sachin Mittal <[EMAIL PROTECTED]> wrote: > > Classes can also have an entity relationship among themselves. > I have few question on how can we relate classes in xwiki. Let me start by > posting a simple example: > Say our application has two classes Product and Review. Relationship between > them is a product can have multiple reviews. > Now I can relate these classes in following way: > 1. Create a product document and add the product object to it. All the > reviews for that product are also added to that product document as review > objects. Thus I have grouped reviews to a product.
This way is the simpliest one, cons : - not scalable since document load/save speed depends on the number of objects it holds. - objects cannot be queried from the public API (meaning no ordering on field values for example) - notifications (by email for example) are hard to write (which object has been modified in this save ?) > 2. Create a product document and add the product object to it. For each > review for that product created a review document and add review object to > that review document and make review document child of product document. > Thus I have arranged reviews as children of a product. Best way to do it imho, pros : - scalable - no need to create author, date, title, etc fields in your Review class - methods needed to get relationships are already present in the Document API (get childs, parent) - allow complex queries like ordering the reviews by some criteria (creation date, mod date, author, etc) - easy to write fine-grained notifications (review creation/modification/deletion) > 3. In the review class add a db list field, which refers to objects of > product class. While creating a review object choose the right product name > from the list. Thus reviews are associated to a product. I've tried this in the past but I had some perf issues with the db list displayer. It also appeared that choosing an item in a long list when it was possible to imply the parent from the parent sheet wasn't effective from the user POV. BTW this behavior can be emulated with some custom parent displayer. Hope this helps, -- Jean-Vincent Drean _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs

