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.
My 'party' entity doesn't actually need any properties:
$p = array();
$p = (object) $p;
entity_save('party', $p);
dsm($p);
The above code appears to fail.
Comment | File | Size | Author |
---|---|---|---|
#36 | write-empty-row.patch | 2.49 KB | jbrown |
#35 | write-empty-row-d7.patch | 2.49 KB | jbrown |
#31 | write-empty-row.patch | 2.54 KB | jbrown |
#31 | write-empty-row-d7.patch | 2.49 KB | jbrown |
#29 | write-empty-row-test-only.patch | 898 bytes | jbrown |
Comments
Comment #1
klausiWhat is the hook_entity_info() implementation for your party entity? Do you implement a controller class that takes care of the saving?
Comment #2
joachim CreditAttribution: joachim commentedSo far I'm using the built-in one the docs recommend.
Comment #3
fagoI guess the problem is an exception, you are not seeing due to a bug. See #973116: drupal_write_record() fails when saving new entity. If not, please re-open.
Comment #4
joachim CreditAttribution: joachim commentedThis is still producing no result in the DB and an empty message with code updated about an hour ago.
(Not that it matters all that much if the status property is required; that means all entities need at least one key!)
Comment #5
joachim CreditAttribution: joachim commentedOh, misread the other bug's resolution -- status is not required :)
Comment #6
fagogreat :)
Comment #7
joachim CreditAttribution: joachim commentedNo, that means this is still active!
If status WERE required, then you'd always have at least one property. But that's not the case.
Comment #8
fago!? Sry, I don't get what's the issue here? You want to be able to build entity types without properties?
Comment #9
joachim CreditAttribution: joachim commentedYup!
Comment #10
klausiWhy? You want to have entities that do not contain any data? Hm, then the only reasonable information that you store is the amount of entities. You can implement a counter more easily, or do I miss something?
Comment #11
joachim CreditAttribution: joachim commentedParty module.
A party is a groupings of profile entities that do not need to have a uid.
So far, I've no need for any data on a party apart from its ID. I still need an admin UI to list them and give links to some (yet to be built) page that shows you a single party by (somehow) grouping together its profile entities.
... Then there's the party edit page. No idea how the form for that's going to work :/
Comment #12
klausiThen it should be sufficient to just create an empty party entity and pass it to the edit form where the actual input/selection of profiles happens. No need to save() beforehand.
For the edit page: you will have to implement something like (assuming 'party' is the machine name of your entity type)
function party_form($form, &$form_state, $party, $op = 'edit') { }
for an example see wsclient_ui.inc
Comment #13
joachim CreditAttribution: joachim commented> Then it should be sufficient to just create an empty party entity and pass it to the edit form where the actual input/selection of profiles happens. No need to save() beforehand.
The edit form is likely to be pretty hairy because it's going to have to solve the problem of multiple entity forms within one form.
Also, even once those profile entities are created, there's still no properties to save in the party!
Comment #14
fago>Also, even once those profile entities are created, there's still no properties to save in the party!
I guess you'll need to store references on profiles, thus profile ids? Or are you using a field for that?
Still you'll need at least an entity identifier - have you defined that in your hook_schema()? If so, are you getting an error message when saving?
Comment #15
joachim CreditAttribution: joachim commentedI'm not sure how I'll store them yet -- at least at the moment, probably in a custom table. At CPH some sort of entity relationship managing API was raised as an idea.
> Still you'll need at least an entity identifier - have you defined that in your hook_schema()? If so, are you getting an error message when saving?
Yup, there's a party id. But when saving a new one, that's not set. So it's just an empty array.
Comment #16
fagoCan I find the code somewhere, so I'd have a look.
Comment #17
fagoComment #18
joachim CreditAttribution: joachim commentedYup, will post the code soon... I'd lost my github password :/
Comment #19
Damien Tournoud CreditAttribution: Damien Tournoud commentedThis is a core bug.
drupal_write_records()
cowardly refuses to save an empty (ie. only defaults) row.Comment #20
jbrown CreditAttribution: jbrown commentedThere is no function called drupal_write_records().
Comment #21
jbrown CreditAttribution: jbrown commentedComment #22
Damien Tournoud CreditAttribution: Damien Tournoud commentedWe probably need a ->useDefaults() here.
Comment #23
jbrown CreditAttribution: jbrown commentedI'm on it!
Comment #24
jbrown CreditAttribution: jbrown commentedComment #25
jbrown CreditAttribution: jbrown commented#24: write_empty_row.patch queued for re-testing.
Comment #26
jbrown CreditAttribution: jbrown commented#24: write_empty_row.patch queued for re-testing.
Comment #27
jbrown CreditAttribution: jbrown commented#24: write_empty_row.patch queued for re-testing.
Comment #29
jbrown CreditAttribution: jbrown commentedComment #30
joachim CreditAttribution: joachim commentedI applied this to 7.x (my 8.x needs reinstalling...) and successfully wrote an empty entity to the database.
Nearly RTBC, just a formatting nitpick:
Comment is missing a full stop.
While we're at it, I think this could do with a comment to explain it, especially as finding docs on useDefaults() seems a bit tricky.
6 days to next Drupal core point release.
Comment #31
jbrown CreditAttribution: jbrown commenteduseDefaults() docs are readily available on api.drupal.org ;-)
http://api.drupal.org/api/drupal/core--includes--database--query.inc/fun...
Comment #32
joachim CreditAttribution: joachim commentedTook me about six google searches to find them though! :/
Tests still pass, comments are good. RTBC :)
Comment #33
catchLooks good to me and nice test addition. Committed/pushed to 8.x, moving back to 7.x. Please re-upload the 7.x patch so the test bot can run it.
Comment #34
catchComment #35
jbrown CreditAttribution: jbrown commentedComment #36
jbrown CreditAttribution: jbrown commentedTry again...
Comment #37
tim.plunkettFixing tag.
Comment #38
joachim CreditAttribution: joachim commented#36: write-empty-row.patch queued for re-testing.
Comment #39
joachim CreditAttribution: joachim commentedTests pass, setting RTBC.
Comment #40
jbrown CreditAttribution: jbrown commentedWow - that's an oldie!
Comment #41
David_Rothstein CreditAttribution: David_Rothstein commentedHm, this makes sense but I'm not sure about it for Drupal 7. Trying this:
Before the patch it's a no-op. After the patch it's a PDO exception. Granted that's a mistake in your code, but maybe we want to find a kinder way to indicate it in Drupal 7?
The patch also changes the NULL return value in case of a no-op, although I guess that was never documented.
Comment #42
David_Rothstein CreditAttribution: David_Rothstein commentedWon't this also fail with an error if $fields is empty? (I noticed the patch has no test coverage for the update case, only the insert case.)
This part might affect Drupal 8 too.
Comment #43
mgiffordLooking for D8 feedback on "Won't this also fail with an error if $fields is empty?" from @David_Rothstein in #42.
We should be sure this is fixed in D8 before back-porting it to D7.
@David_Rothstein - I also don't know what "kinder way to indicate" this we are available. I think it would be better than what we have now.
Comment #44
jhedstromIf this is still an issue in 8, the patch from 3 years ago definitely needs reroll.
Comment #45
jbrown CreditAttribution: jbrown commented"drupal_write_record() and drupal_schema_fields_sql() removed in favor of merge queries and entity API"
https://www.drupal.org/node/2340291
Comment #46
chx CreditAttribution: chx commentedAye but Insert::preExecute will silently quit (in D8 too) if you make a query that uses only defaults, check the last return statement, it's missing a defaultFields check.
Edit: amateescu found this.
Comment #52
daffie CreditAttribution: daffie commentedComment #53
daffie CreditAttribution: daffie commented