Difference between revisions of "Truxton relation set relation"

From truxwiki.com
Jump to navigation Jump to search
(Created page with "This sets the type of the relationship between two objects. This corresponds to the <code>[RelationTypeID]</code> column of the the <code><nowiki>[</nowiki>Relation Table|Re...")
 
Line 1: Line 1:
This sets the type of the relationship between two objects.
+
This sets the type of the relationship between two objects in Truxton.
 
This corresponds to the <code>[RelationTypeID]</code> column of the the <code><nowiki>[</nowiki>[[Relation Table|Relation]]<nowiki>]</nowiki></code> table in the database.
 
This corresponds to the <code>[RelationTypeID]</code> column of the the <code><nowiki>[</nowiki>[[Relation Table|Relation]]<nowiki>]</nowiki></code> table in the database.
  
 
=Syntax=
 
=Syntax=
 
<source lang="C">
 
<source lang="C">
void truxton_relation_set_relation_type(uint64_t relation_handle, uint64_t type);
+
void truxton_relation_set_relation(uint64_t relation_handle, uint64_t type);
 
</source>
 
</source>
  
Line 15: Line 15:
 
The type of the relationship.
 
The type of the relationship.
 
It should be one of the [[Relation Types|defined constants]], it will be stored in the <code>[RelationTypeID]</code> column of the <code><nowiki>[</nowiki>[[Relation Table|Relation]]<nowiki>]</nowiki></code> table.
 
It should be one of the [[Relation Types|defined constants]], it will be stored in the <code>[RelationTypeID]</code> column of the <code><nowiki>[</nowiki>[[Relation Table|Relation]]<nowiki>]</nowiki></code> table.
 +
This value should be one of the values from the <code>[ID]</code> column of the <code>[RelationType]</code> reference table in the database.
  
 
=Sample=
 
=Sample=

Revision as of 07:40, 17 January 2021

This sets the type of the relationship between two objects in Truxton. This corresponds to the [RelationTypeID] column of the the [Relation] table in the database.

Syntax

void truxton_relation_set_relation(uint64_t relation_handle, uint64_t type);

Parameters

relation_handle

The relation object. This handle comes from calling truxton_relation_create().

type

The type of the relationship. It should be one of the defined constants, it will be stored in the [RelationTypeID] column of the [Relation] table. This value should be one of the values from the [ID] column of the [RelationType] reference table in the database.

Sample

void set_primary_photo( uint64_t truxton, uint64_t media, uint64_t child_file )
{
   char media_id[ 65 ];
   char file_id[ 65 ];
   
   truxton_media_get_id( media, media_id, sizeof( media_id ) );
   truxton_child_file_get_id( child_file, file_id, sizeof( file_id ) );

   uint64_t relation = truxton_relation_create( truxton );

   // Now tell Truxton that child_file (A object) is the primary photo of media (B object)
   truxton_relation_set_relation( relation, RELATION_PRIMARY_PHOTO );

   // Set the A object, A is a file
   truxton_relation_set_a_id( relation, file_id );
   truxton_relation_set_a_type( relation, OBJECT_TYPE_FILE );

   // Set the B object, B is a piece of media
   truxton_relation_set_b_id( relation, media_id );
   truxton_relation_set_b_type( relation, OBJECT_TYPE_MEDIA );

   // Set the source object, source is a piece of media
   truxton_relation_set_source_id( relation, media_id );
   truxton_relation_set_source_type( relation, OBJECT_TYPE_MEDIA );

   // Commit the data to the database
   truxton_relation_save( relation );
   truxton_relation_destroy( relation );
}