Closed (fixed)
Project:
Drupal core
Version:
7.x-dev
Component:
field system
Priority:
Critical
Category:
Bug report
Assigned:
Reporter:
Created:
6 Mar 2009 at 04:05 UTC
Updated:
27 Mar 2009 at 14:40 UTC
Jump to comment: Most recent file
Switch the field_config and field_config_instance tables to use a serial primary key, and (probably) join fci to fc based on the pkey, not on the field name.
Consider switching the serial pkey on field data tables, too. I do not think anything will ever join to them but I believe there are good reasons for doing so anyway (e.g. storage locality).
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | field-ids-doc-392686-17.patch | 1.77 KB | yched |
| #15 | empty.patch | 0 bytes | bjaspan |
| #8 | field-primary-key-392686-8.patch | 18.39 KB | bjaspan |
| #7 | field-primary-key-392686-7.patch | 6.78 KB | yched |
| #5 | field-primary-key-392686-5.patch | 7.63 KB | bjaspan |
Comments
Comment #1
bjaspan commentedThis patch implements the straightforward conversion of field_config and field_config_instance to use serial primary keys. field_read_instances uses the field_id instead of field_name to join. The entire API still works in terms of field_name.
This will help/make possible batch delete and a host of other things.
Comment #2
yched commentedMainly doc comments
- Double spacing ;-)
- Maybe the PHPdoc at the beginning of field.crud.inc should state more cleanly "internal" for id and field_id ?
- "The id property is ignored" for field_create_field() and field_create_instance() : Could we say instead that the id keys will be automatically generated ?
Other than that, RTBC if it passes the tests I guess.
Comment #3
bjaspan commentedI fixed the double spacing; sorry, in grade school I was taught that two spaces are correct and one space is wrong. :-) I changed the PHPdoc to say the ids are "managed automatically" (they are not always generated, sometimes they are copied).
The id and field_id fields are not just internal, just like $node->nid is not internal. They are the primary identifiers and foreign keys for these objects. Other modules are free/encouraged to use them for joins etc.
Since yched's comments were all doc-related and I addressed them, RTBC.
Comment #4
dries commentedI'm having trouble understanding the difference between the id and the field_id based on the PHPdoc. It might be a language issue but the "by" in "attached by" confuses me. I think this ought to be clarified a bit better in the PHPdoc. Can we try to explain it a bit better/different?
Comment #5
bjaspan commented@dries: Fair point. First, review the intro paragraph of the Field API data structures doc:
Now, I've changed the PHPdoc for the Field Instance structure (mainly by adding the phase "foreign key"). Does this clear it up?
Comment #6
dries commentedYep, that is a subtle but valuable improvement. I'll commit it tomorrow morning unless someone has a better suggestion. Thanks, bjaspan.
Comment #7
yched commentedMinor changes :
- adds the term 'read-only' to the 'id' and 'field_id' properties descriptions, like we do for 'active', 'deleted', 'columns'. That's what I meant when I erroneously used the word 'internal' in #2-2, but Barry's right, they are not 'internal'.
- suggests "The id and field_id properties are assigned automatically" instead of "... are managed automatically", which is less clear IMO.
Depending on Barry's opinions on the above, either this patch or #5 are RTBC.
Comment #8
bjaspan commented@yched: I like your changes, but made two more:
1. You missed a use of the "managed automatically," I updated it.
2. It isn't just id and field_id that are assigned automatically, it is all read-only properties. If a property *isn't* assigned automatically, it isn't read only, and shouldn't be marked as such. So I changed everywhere that said "id is assigned automatically" to "read-only properties are assigned automatically."
Now, I am sorta wondering whether we should even that say that at all, because the whole point of documenting that it is read-only is to concisely identify that it is READ ONLY and cannot be set, changed, etc. from outisde the API. If all Drupal APIs documented their data structures as Field API does (oh, happy day!), would we really want all of them to say "read-only properties are assigned automatically"? It seems redundant.
Anyway, we're just tweaking the documentation. The most recent version of the patch can be committed at any time. :-)
Comment #9
yched commentedI agree that "read-only properties are assigned automatically" in the PHPdoc field_create_*() crud seems redundant.
It adresses the potential uncertainty about stuff like :
Can I create fields and instances from existing ones, like
$new_field = $existing_field;
$new_field['field_name'] = 'new_field';
field_create_field($new_field);
(yes you can)
It's especially touchy for id properties because nodes don't work that way : if you want to create a new node, you have to unset its id. Our ids here are *really* transparent. API-wise, the field is identified by it's field_name.
Other 'read-only' properties will go unnoticed by most, but I think ids will puzzle people, esp. since they currently sit at the top of the descriptions of the $field and $instance structures.
[edit : AAMOF, I'd vote to put them somewhere down the list. They're here for internal db performance only, people should barely be aware that they exist]
Comment #10
dries commentedI've committed the patch in #8, however, I'm setting the status to 'code needs work' because of the feedback in #9. The feedback in #9 are incremental improvements so I figured I'd go ahead and get #8 in. Thanks so far! :)
Comment #11
yched commentedLooks like #370480: Field form cleanup sneaked in the same commit (was marked RTBC anyway)
Comment #12
bjaspan commentedI disagree that the ids are for internal purposes only and should be moved down the list. It is true that our API treats fields as identified by name, not by id, but that is a holdover from not having ids and I suspect it will eventually change. Any module that wants to use the Field CRUD hooks to do extra stuff will want to use field id instead of name as the foreign key, at which point there will be strong incentive to change the API to use ids for real. Also, I suspect implementing the batch delete and/or the ability to create, delete, and re-create a field named 'foo' will require changing our concept of "field names are unique" in one way or another; the field ids will be unique instead.
So, I think the PHPdoc re: id and field_id is fine for now. If/when we change the API as discussed above, that will be a separate issue. Therefore, I suggest that this issue really is fixed.
yched, if you agree, please set to RTBC so hopefully Dries will mark it fixed. :-)
Comment #13
bjaspan commentedComment #15
bjaspan commentedHeh, that's funny. There is no new patch, so the testbot is trying to re-apply the patch from #8 that has already been applied and thus fails. Let's see if an empty patch file works around the proboem.
Please review the comment in #12.
Comment #16
yched commentedNot sure what you mean by 'change the API to use [numeric] ids for real'. Moving to serial ids as primary field id instead of field name has serious drawbacks, because the ids are then local to a given setup, and depend on the order of field creation, etc... One of the pains in flexinode : obscure numeric-based snippets that you cannot move from one site to another, or from dev to staging to production.
Numeric ids need to stay internal / storage related. To the outside world, the field_name string is the field identifier.
Batch delete might require moving from "unique field_name" to "unique (field_name, deleted = 0)", and, granted, contrib modules that want to store additional metadata about fields will need to use the numeric id as their storage PK. That's still 'internal' to me. For the vast majority of field_crud users (modules that create fields in their install() hook), the numeric ids are something they need not be aware of.
Still voting for making the ids less prominent on the field and instance properties doc :-). I'll try to wrap a proposal patch when I get access to my coding env.
Comment #17
yched commentedOK, I feel like I'm turning this in a bikeshed issue.
Attached patch keeps the docs for the ids where they are, makes it explicit that they are assigned or populated automatically by field_create_field() / field_create_instance(), and removes the 'Read-only properties are assigned automatically' bits.
Comment #18
bjaspan commentedLooks fine to me.
Comment #19
dries commentedCommitted. Fixed. Thanks. :)