3093 Posts in 875 Topics by 654 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 815 Views |
-
How do I get all objects indirectly referred to by another?

26 May 2011 at 9:48am
I have a collection of object classes with the following relations:
- Class 1 has many objects of Class 2
- Class 2 has many objects of Class 3
- Class 3 is just another data classThat is, a single Class 1 object has multiple Class 2 objects which in turn have multiple Class 3 objects.
How would I execute a query to get all objects of Class 3 that are indirectly referred to by Class 1? Can this be done efficiently? Or do I need to add a Class 1 has_one relation to class 3 (something which sounds ugly and would prefer to avoid)? This is an operation that might be done often, so it needs to be efficient.
Hans
-
Re: How do I get all objects indirectly referred to by another?

26 May 2011 at 8:02pm
Well you can't get all the Class 3 objects indirectly without getting the other classes. You'll need the id's. It depends on your dataset size, using the ORM (so ClassOne->Relationship()->Relationship() will return what you want but would be slow.
You could also use DataObject::get with a join clause (get Class 3, join on class 2) which would be pretty quick. I suggest you try with a simply join operation with DataObject get and see how performance goes. Cache if required. Next level in optimization is to denormalize your data, thus removing the need for joins.
| 815 Views | ||
|
Page:
1
|
Go to Top |


