relation_add (public)

 relation_add [ -form_id form_id ] [ -extra_vars extra_vars ] \
    [ -variable_prefix variable_prefix ] \
    [ -creation_user creation_user ] [ -creation_ip creation_ip ] \
    [ -member_state member_state ] rel_type object_id_one \
    object_id_two

Defined in packages/acs-subsite/tcl/relation-procs.tcl

Creates a new relation of the specified type between the two objects. Throws an error if the new relation violates a relational constraint.

Switches:
-form_id
(optional)
The form id from templating form system
-extra_vars
(optional)
An ns_set of extra variables
-variable_prefix
(optional)
Only form elements that begin with the specified prefix will be processed.
-creation_user
(optional)
The user who is creating the relation
-creation_ip
(optional)
-member_state
(optional)
Only used for membership_relations. See column membership_rels.member_state for more info.
Parameters:
rel_type
object_id_one
object_id_two
Returns:
The rel_id of the new relation
Authors:
Michael Bryzek <mbryzek@arsdigita.com>
Ben Adida <ben@openforce.net>
Created:
1/5/2001

Partial Call Graph (max 5 caller/called nodes):
%3 test_acs_subsite_check_composite_group acs_subsite_check_composite_group (test acs-subsite) relation_add relation_add test_acs_subsite_check_composite_group->relation_add test_acs_subsite_expose_bug_775 acs_subsite_expose_bug_775 (test acs-subsite) test_acs_subsite_expose_bug_775->relation_add test_acs_subsite_rel_segment_new acs_subsite_rel_segment_new (test acs-subsite) test_acs_subsite_rel_segment_new->relation_add test_acs_subsite_relation_procs acs_subsite_relation_procs (test acs-subsite) test_acs_subsite_relation_procs->relation_add db_string db_string (public) relation_add->db_string db_transaction db_transaction (public) relation_add->db_transaction package_instantiate_object package_instantiate_object (public) relation_add->package_instantiate_object group::add_member group::add_member (public) group::add_member->relation_add install::xml::action::relation-add install::xml::action::relation-add (public) install::xml::action::relation-add->relation_add packages/acs-subsite/www/admin/groups/new.tcl packages/acs-subsite/ www/admin/groups/new.tcl packages/acs-subsite/www/admin/groups/new.tcl->relation_add packages/acs-subsite/www/admin/parties/new.tcl packages/acs-subsite/ www/admin/parties/new.tcl packages/acs-subsite/www/admin/parties/new.tcl->relation_add packages/acs-subsite/www/admin/users/new.tcl packages/acs-subsite/ www/admin/users/new.tcl packages/acs-subsite/www/admin/users/new.tcl->relation_add

Testcases:
acs_subsite_expose_bug_775, acs_subsite_check_composite_group, acs_subsite_relation_procs, acs_subsite_rel_segment_new
Source code:
    # First check if the relation already exists, and if so, just return that
    set existing_rel_id [db_string rel_exists {
        select rel_id
        from   acs_rels
        where  rel_type = :rel_type
        and    object_id_one = :object_id_one
        and    object_id_two = :object_id_two
    } -default {}]

    if { $existing_rel_id ne "" } {
        return $existing_rel_id
    }

    set var_list [list  [list object_id_one $object_id_one]  [list object_id_two $object_id_two]]

    # Note that we don't explicitly check whether rel_type is a type of
    # membership relation before adding the member_state variable.  The
    # package_instantiate_object proc will ignore the member_state variable
    # if the rel_type's plsql package doesn't support it.
    if {$member_state ne ""} {
        lappend var_list [list member_state $member_state]
    }

    # We initialize rel_id, so it's set if there's a problem
    set rel_id {}

    # We use db_transaction inside this proc to roll back the insert
    # in case of a violation

    db_transaction {

        set rel_id [package_instantiate_object  -creation_user $creation_user  -creation_ip $creation_ip  -start_with "relationship"  -form_id $form_id  -extra_vars $extra_vars  -variable_prefix $variable_prefix  -var_list $var_list  $rel_type]

        # Check to see if constraints are violated because of this new
        # relation

        # JCD: this is enforced by trigger so no longer check explicitly
        # see membership_rels_in_tr
        #
        # set violated_err_msg [db_string select_rel_violation {} -default ""]
        #
        # if { $violated_err_msg ne "" } {
        #     error $violated_err_msg
        # }
    } on_error {
        return -code error $errmsg
    }

    return $rel_id
Generic XQL file:
packages/acs-subsite/tcl/relation-procs.xql

PostgreSQL XQL file:
<fullquery name="relation_add.select_rel_violation">
    <querytext>
        select rel_constraint__violation(:rel_id) 
      </querytext>
</fullquery>
packages/acs-subsite/tcl/relation-procs-postgresql.xql

Oracle XQL file:
<fullquery name="relation_add.select_rel_violation">
    <querytext>
      
	    select rel_constraint.violation(:rel_id) from dual
	
      </querytext>
</fullquery>
packages/acs-subsite/tcl/relation-procs-oracle.xql

[ hide source ] | [ make this the default ]
Show another procedure: