0

I have a Drupal content type that includes Zip Codes (Postal Codes). An unlimited number of Zip Codes is allowed, and the Zip Codes are defined in the "Allowed Values List" in the field definition. I have many Zip Codes that I need to insert, and have them staged them and their relationship to nodes in a temporary database table.

I do the following insert to both "field_data_field_zip_codes" and "field_revision_field_zip_codes", but I still do not see the values in the online Content.

Has someone done this type of thing before, and know what I am missing? I looked at using "Feeds" but that module doesn't seem to support multi-value fields, just flat tables.

INSERT INTO  field_revision_field_wp_zip_codes
SELECT c.entity_type                     AS entity_type
      ,'wp_content_component'            AS bundle
      ,0                                 AS deleted
      ,c.entity_id                       AS entity_id
      ,c.entity_id                       AS revision_id
      ,'und'                             AS language
      ,(@rownum:=@rownum+1) - 1          AS delta
      ,z.zip                             AS field_wp_zip_codes_value
FROM field_data_field_wp_cc_id c 
  INNER JOIN cc_zips z 
     ON z.cc = c.field_wp_cc_id_value,
     (SELECT @rownum:=0) r
 WHERE z.cc = '1039'
 AND c.entity_id = '3699';

migrated from stackoverflow.com Jul 18 '12 at 15:34

This question came from our site for professional and enthusiast programmers.

0

As for any application, unless you are perfectly sure of what you are doing, are comfortable with it and have a good understanding of the inner working of the Field API and the SQL storage engine for fields, you shouldn't try to do your insert directly in SQL.

Instead, you should use the Node or Entity APIs to load your contents, update them and save them back in PHP code. This will be more expensive performance-wise, but much more easier to implement and maintain.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.