Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Is there a recommended way to share a single serial field between two node types?
Would changing serial.inc:
function _serial_get_table_name($field) {
return db_escape_table( // be on the safe side
'serial_' . $field['type_name'] . '_' . $field['field_name']);
}
to
function _serial_get_table_name($field) {
return db_escape_table( // be on the safe side
'serial_' . $field['field_name']);
}
suffice? albeit make all serial fields shared which is OK for this application?
any advice appreciated, thanks
DT
Comments
Comment #1
kirsh CreditAttribution: kirsh commentedSharing the table by several types also requires changing the activity when a new field is added (currently the table is created) and removed (the table is dropped and the remaining fields will not have any table). I think that that is but there might be other issues.
Comment #2
davidwhthomas CreditAttribution: davidwhthomas commentedThanks for the reply, yes that would be the case. I was looking into checking if the table exists prior to creation and checking if it's used by other types prior to delete.
In any case, for the time being I've ended up using a postgres sequence with a cck computed field as I'd rather not hack on the serial module which is great for per type serial values.
and for the computed field:
Possibly in the future shared field support could be added however.
Nevertheless, cool module, thanks for the help.
DT
Comment #3
colanNo new features for D6.
Comment #4
ikeigenwijs CreditAttribution: ikeigenwijs commentedWhen a serial field is reused on a different contenttype it would be logical that the serial field counts upwards.
Use case:
1 incremental numer shared over multiple contenttypes but not all.
Its still posible to use a per contenttype serial field.
But it would also be posible to share a serial field.
example:
contenttype Article:
contenttype Page:
Adding new contenttype
add new Article: Serial_article_1 (1) ,Serial_shared (1)
add new Article: Serial_article_1 (2) ,Serial_shared (2)
add new Page: Serial_page_1 (1) ,Serial_shared (3)
add new Page: Serial_page_1 (2) ,Serial_shared (4)
add new Article: Serial_article_1 (3) ,Serial_shared (5)
s
Comment #5
MustangGB CreditAttribution: MustangGB commentedPossible quick and dirty fix, not fully tested.
serial.inc
Comment #6
MustangGB CreditAttribution: MustangGB commentedFollow-up comment to say I've been using #5 for the last 3 months, it works as expected and I haven't ran into any issues.
Comment #7
Eric_A CreditAttribution: Eric_A commentedI don't have the time right now, but I think this could/should be implemented as a field setting with full BC.
Here is a snippet that is #5 re-rolled against 7.x-1.8 and with some added comments. Of course this type of change is a use-at-your-own-risk-if-you-think-you-know-what-you-are-doing.