浏览代码

Fixed a bug in when adding new records to a base table without a type_id field

Stephen Ficklin 8 年之前
父节点
当前提交
c3bdbfc710

+ 1 - 1
tripal_chado/includes/fields/chado_base__organism_id.inc

@@ -166,7 +166,7 @@ class chado_base__organism_id extends TripalField {
     // Set some defaults for the empty record.
     $entity->{$field_name}['und'][0] = array(
       'value' => '',
-      'organism__type_id' => '',
+      'organism__organism_id' => '',
     );
 
     if ($record) {

+ 7 - 6
tripal_chado/includes/tripal_chado.field_storage.inc

@@ -40,13 +40,14 @@ function tripal_chado_field_storage_write($entity_type, $entity, $op, $fields) {
   // Convert the fields into a key/value list of fields and their values.
   $field_vals = tripal_chado_field_storage_write_merge_fields($fields, $entity_type, $entity);
 
-  // Write the record for the base table.  First get the values for this table
-  // and set the record_id (update) or the type_id (insert)
+  // First, write the record for the base table.  If we have a record id then
+  // this is an upate and we need to set the primary key.  If not, then this
+  // is an insert and we need to set the type_id if the table supports it.
   $values = $field_vals[$base_table][0];
   if ($record_id) {
     $values[$base_pkey] = $record_id;
   }
-  else {
+  elseif ($type_field) {
     $values[$type_field] = $cvterm->cvterm_id;
   }
   $base_record_id = tripal_chado_field_storage_write_table($base_table, $values);
@@ -107,7 +108,7 @@ function tripal_chado_field_storage_write_table($table_name, $values) {
    $fkeys = $schema['foreign keys'];
    $pkey = $schema['primary key'][0];
 
-   // Before inserting or updating this table, recruse if there are any
+   // Before inserting or updating this table, recurse if there are any
    // nested FK array values.
    foreach ($values as $column => $value) {
      // If this value is an array then it must be a FK... let's recurse.
@@ -157,7 +158,7 @@ function tripal_chado_field_storage_write_table($table_name, $values) {
      // Insert the values array as a new record in the table.
      $record = chado_insert_record($table_name, $values);
      if ($record === FALSE) {
-       throw new Exception('Could not insert Chado record into table: "' . $tablename . '".');
+       throw new Exception('Could not insert Chado record into table: "' . $table_name . '".');
      }
      return $record[$pkey];
    }
@@ -167,7 +168,7 @@ function tripal_chado_field_storage_write_table($table_name, $values) {
      // not being tested for here.
      $match[$pkey] = $values[$pkey];
      if (!chado_update_record($table_name, $match, $values)) {
-       drupal_set_message("Could not update Chado record in table: $tablename.", 'error');
+       drupal_set_message("Could not update Chado record in table: $table_name.", 'error');
      }
      return $values[$pkey];
    }