ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Setting/maintaining relationship connection

November 17, 2012 12:18pm

Subscribe [1]
  • #1 / Nov 17, 2012 12:18pm

    PixelJunction

    16 posts

    I’ve setup a primary channel ‘project’ for my latest website.

    I have numerous other channels that will serve as the children channels to this; on each of those I’ve identified one field as the relationship link which should simulate my foreign key relationship back to the parent.

    When creating a child entry from the front end, I was creating the connection to the parent by assigning the project entry_id as a hidden field in my SafeCracker form:

    <table>
    <tr><td class='form_text'>Member Position:</td><td>{field:member_entry_type}</td></tr>
    <tr><td class='form_text'>First Name:</td><td>{field:member_first_name}</td></tr>
    <tr><td class='form_text'>Last Name:</td><td>{field:member_last_name}</td></tr>
    <tr><td colspan='2'>
        <input type='hidden' id='volunteer_entry_race_id' name='member_entry_project_id' value='{segment_3}'/>
        <input type='hidden' id='title' name='title' value='Member Entry - <?php echo $title; ?>'/>
        <input type="submit" value="Submit">
    </td></tr></table>

    This works when I assign the value, but any time I try to reference the value down the road, it doesn’t pull the right value. In the example below, segment_3 is the parent_id. I was just trying out an update_entry API call, but when I echo the project ID I previously set, that’s where I display the unexpected value.

    $child_id = '{segment_3}';
    
    $this->EE->load->library('api');
    $this->EE->api->instantiate('channel_entries');
    $this->EE->api->instantiate('channel_fields'); 
    
    {exp:channel:entries channel="member_entries" entry_id="{segment_3}"}
    
     echo '{member_entry_project_id}';
    
     $data = array(
      'channel_id'  => 10,
      'title'       => '{title}',
      'entry_date'  => {entry_date},
      'field_id_49' => '{member_entry_project_id}',
      'field_ft_49' => 'none',
      'field_id_50' => '{member_entry_type}',
      'field_ft_50' => 'none',
      'field_id_51' => '{member_first_name}',
      'field_ft_51' => 'none',
      'field_id_51' => '{member_last_name}',
      'field_ft_52' => 'none'
     );
    
    {/exp:channel:entries}
    ?>

    In researching other posts, it appears I’m pulling back the relationship ID and not the parent ID I originally set. This lead me to think that I was approaching this incorrectly. Is there another way I should approach this?

    Thanks,

     

     

  • #2 / Nov 20, 2012 12:19pm

    Dan Decker

    7338 posts

    Hi PixelJunction,

    You need to setup you form elements using this prototype:

    <input type="text" name="my_field_name" id="my_field_name" value="{my_field_name}">
    {field:my_field_name}
    
    <select name="my_field_name" id="my_field_name">
            {options:my_field_name}
                    <option value="{option_value}"{selected}>{option_name}</option>
            {/options:my_field_name}
    </select>

    Let me know if you have any questions!

    Cheers,

  • #3 / Nov 24, 2012 10:46am

    PixelJunction

    16 posts

    Thanks Dan - let me try it out and I’ll let you know!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases