Drupal 7.12 - adding a Serial field to a profile works fine, but when the profile is edited Drupal throws an error:

Notice: Undefined property: Profile::$nid in serial_field_insert() (line 83 of /var/www/html/sites/all/modules/serial/serial.module).

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'nid' cannot be null: INSERT INTO {serial_main_field_prof_amb_id} (nid) VALUES (:db_insert_placeholder_0); Array ( [:db_insert_placeholder_0] => ) in _serial_generate_value() (line 155 of /var/www/html/sites/all/modules/serial/serial.inc).
CommentFileSizeAuthor
#4 profilefix-1552280-4.patch843 bytescthos

Comments

Randeep.Singh’s picture

I also got similar kind of error while creating new user. please help and explain..

TYPE php

DATE Monday, October 29, 2012 - 01:31

USER admin

LOCATION http://localhost:8080/website/admin/people/p2rp-create/doctor

REFERRER http://localhost:8080/website/admin/people/p2rp-create/doctor

MESSAGE PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'nid' cannot be null: INSERT INTO {serial_doctor_field_serial} (nid) VALUES (:db_insert_placeholder_0); Array ( [:db_insert_placeholder_0] => ) in _serial_generate_value() (line 155 of C:\wamp\www\website\sites\all\modules\serial\serial.inc).

SEVERITY error

HOSTNAME 127.0.0.1

OPERATIONS

ytsejam’s picture

Unfortunately I have the same problem.

BParticle’s picture

Same kind of error when adding a Serial field to an entityform submission

Notice: Undefined property: Entityform::$nid in serial_field_insert() (line 83 of /var/www/drupal-7.17-testing/sites/all/modules/serial/serial.module).
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'nid' cannot be null: INSERT INTO {serial_registration_form_field_registration_id} (nid) VALUES (:db_insert_placeholder_0); Array ( [:db_insert_placeholder_0] => ) in _serial_generate_value() (line 155 of /var/www/drupal-7.17-testing/sites/all/modules/serial/serial.inc).
1048 Column 'nid' cannot be null

I'm not a php expert, but this error probably just points to the fact that both profiles and entityform submissions don't have a NID, as profiles have UID's and submissions of an entityform share the same NID of the parent node.

Just for testing purposes I changed line 83
$sid = _serial_generate_value($entity->nid, $instance['bundle'], $field['field_name']);
into

if ($entity->nid) {
      $entitynid = $entity->nid;
    } else $entitynid = '000';
    $sid = _serial_generate_value($entitynid, $instance['bundle'], $field['field_name']);

THIS IS NOT A SOLUTION BY FAR (like I said, I'm not a php person), so please don't replicate. However monstrous and unorthodox, it made saving the entityform submission possible (giving me a different error though), and it made a nice Serial ID as a result. Anyone who knows what he's doing should be able to provide a patch with this information I think.

cthos’s picture

StatusFileSize
new843 bytes

Something like this might do the trick?

It's a little profile2 specific though, so I'd be open to suggestions on how to make it a bit more friendly? Maybe some sort of module invokation to get the appropriate value? The bad news is $entity isn't always a type of Entity, sometimes it is StdClass.

Anyhow, patch!

cthos’s picture

Status: Active » Needs review

Changing status to needs review.

hoporr’s picture

I had the same problem twice now:

1) tried to attach a serial field to the user account. Of course, users don't nids.
2) Then tired to attach the field to the profile. There again, profiles don't have nids.

Seems the code is written to only be able to attach to node CTs.

To make this more general a fix, the check should be made against the entity-key. You can grab that out of the entity_info defintion, and then write a more general test against. Then it should work for any entity.

hoporr’s picture

Priority: Normal » Critical

Raising the status on to critical, as it probably prevents this field/module to be used on any entity besiders node. That is a major show stopper.

hoporr’s picture

Status: Needs review » Closed (duplicate)

I found that this is a duplicate of https://drupal.org/node/1333032 "Add generic entity support"

If the general issue (entity) is solved, then this case here will work as well.