Difference between revisions of "Truxton relation create"
Jump to navigation
Jump to search
(Created page with "This creates an object you can use to form a relationship between two other objects in Truxton. =Syntax= <source lang="C"> uint64_t truxton_relation_create(uint64_t truxton_h...") |
|||
| (2 intermediate revisions by the same user not shown) | |||
| Line 3: | Line 3: | ||
=Syntax= | =Syntax= | ||
<source lang="C"> | <source lang="C"> | ||
| − | uint64_t truxton_relation_create(uint64_t truxton_handle); | + | uint64_t truxton_relation_create( uint64_t truxton_handle ); |
</source> | </source> | ||
=Parameters= | =Parameters= | ||
==<code>truxton_handle</code>== | ==<code>truxton_handle</code>== | ||
| − | The Truxton instance this | + | The Truxton instance this relation will belong. |
This handle comes from calling <code>[[truxton_create]]()</code>. | This handle comes from calling <code>[[truxton_create]]()</code>. | ||
| Line 15: | Line 15: | ||
=Sample= | =Sample= | ||
| + | The following will set the primary photograph of the media. | ||
| + | This establishes the relationship that A is the primary photograph of B. | ||
| + | Specifically, <code>child_file</code> is the primary photograph of <code>media</code>. | ||
<source lang="C" highlight="9"> | <source lang="C" highlight="9"> | ||
| − | void set_primary_photo(uint64_t truxton, uint64_t media, uint64_t child_file) | + | void set_primary_photo( uint64_t truxton, uint64_t media, uint64_t child_file ) |
{ | { | ||
char media_id[ 65 ]; | char media_id[ 65 ]; | ||
| Line 26: | Line 29: | ||
uint64_t relation = truxton_relation_create( truxton ); | 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 ); | 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_id( relation, file_id ); | ||
truxton_relation_set_a_type( relation, OBJECT_TYPE_FILE ); | 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_id( relation, media_id ); | ||
truxton_relation_set_b_type( relation, OBJECT_TYPE_MEDIA ); | 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_id( relation, media_id ); | ||
truxton_relation_set_source_type( relation, OBJECT_TYPE_MEDIA ); | truxton_relation_set_source_type( relation, OBJECT_TYPE_MEDIA ); | ||
| + | // Commit the data to the database | ||
truxton_relation_save( relation ); | truxton_relation_save( relation ); | ||
truxton_relation_destroy( relation ); | truxton_relation_destroy( relation ); | ||
} | } | ||
</source> | </source> | ||
Latest revision as of 09:05, 13 February 2021
This creates an object you can use to form a relationship between two other objects in Truxton.
Syntax
uint64_t truxton_relation_create( uint64_t truxton_handle );
Parameters
truxton_handle
The Truxton instance this relation will belong.
This handle comes from calling truxton_create().
Return value
A handle to a relation object.
Sample
The following will set the primary photograph of the media.
This establishes the relationship that A is the primary photograph of B.
Specifically, child_file is the primary photograph of media.
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 );
}