<< Permissions - Content Groups

Relations between Objects


Relations between objects (e.g. a news article with an associated image) can be easily handled with spunQ as it uses an abstracted relation table in the database being able to combine any objects among each other.

Technically, the creation of relations is done by inserting a new row in the table _relation where all relations of the systems are mapped.

The insert statement will consist of five fields being '_relation_class_ref1', '_relation_object_ref1', '_relation_class_ref2', '_relation_object_ref2' and '_relation_data_order' whose values will be as follows:

Column

Value

_relation_class_ref1

The ID of the class the object being edited belongs to.

_relation_object_ref1

The ID of the object currently being edited.

_relation_class_ref2

The ID of the class the object being associated belongs to.

_relation_object_ref2

The ID of the object currently being associated.

_relation_data_order

A value which controls the relation ordering described above. Initially, this value will be equal with the ID of the current row of the _relation table ('_relation_id').


This fact given, a SQL query to get all associated objects to a given class object – which is often needed in spunQ – would look like that:

SELECT object.* FROM _relation, object
WHERE _relation_class_ref1 = [given class_id] AND
_relation_object_ref1 = [given object_id] AND
_relation_class_ref2 = [id of the class you are looking for relation in] AND
_relation_object_ref2 = object_id

Rarely, the object_ref is entered in the table _relation instead of the object_id. This depends on the context of use, so when you are not getting what you wanted try comparing the _relation_object_1/2 with the field object_ref instead.

A special case is a search for the folder an object resides in. This situation is also mapped in the table _relation. As the struct class (which is responsible for all folders) has the ID 10, just use _relation_class_ref2 = 10 within your query. In this case, the struct_id has to be taken as _relation_object_ref2.


Related Subjects

>> Creating Relations
>> Database Structure

Do you need additional information?

Pose your question

Search