I'm having problems using weight enabled node with dynamic query. From my module code:
// Fetch the data from the database, ordered by weight ascending.
$select = db_select('node', 'n');
// Join tables
$select->join('weight_settings', 'ws', 'n.type = ws.type');
$select->join('weight_weights', 'w', 'n.nid = w.entity_id');
$select->fields('n', array('title', 'nid', 'type'));
$select->fields('w', array('weight'));
$select
->condition('n.status', '1')
->orderBy('weight', 'ASC');
$select->range(0, 50);
If I create a new node with the standard node edit form and accept a default weight = 0, then this new node will not be included in the results of this query. Looking in the database I discovered that at submit a record for the node was not being saved to {weight_weights}.
My work-around was to adjust the content type's default weight to equal '-1'. This saved a value to {weight_weights} and consequently returned the new node as part of the result.
I'm filing a bug, but realize that I also may not be constructing the query correctly. If the latter, recommendations are most welcome.
Also, I noticed that the revised default weight value was not being captured by Features. See http://drupal.org/node/1589948
Cheers!
Comment | File | Size | Author |
---|---|---|---|
#18 | weight-setweight0-1589932-17.patch | 357 bytes | kenficara |
Comments
Comment #1
davisbenThis has been fixed and committed to 7.x-2.x.
Comment #2
mbolli CreditAttribution: mbolli commentedSince the fix I'm getting a PDOException upon saving nodes, because the third field in the weight_weights table is empty but not null. I have temporarily and dirty fixed it like this. It works, but the problem maybe lies elsewhere...
Comment #3
davisbenI'm unable to reproduce the error. Could you provide a little more info about your configuration? One thing to check is that the default weight is being applied to nodes when creating them.
Comment #4
mbolli CreditAttribution: mbolli commentedThanks for your response. Actually it was a node of a content type where I haven't activated weight at all.
What would you like to know about my configuration? It's a Drupal 7.14 installation on Linux with Apache 2, PHP 5 and MySQL 5.
Comment #5
davisbenThat's all I needed, thanks! This has been fixed and committed.
Comment #6
rooby CreditAttribution: rooby commentedMarked #1602692: Undefined property weight_weight in weight_node_insert() (line 342 of weight.module) as duplicate of this issue.
And adding this error message, which is fixed by this commit for the sake of people searching on error messages:
Comment #7
rooby CreditAttribution: rooby commented[removed duplicate post]
Comment #8
bvanmeurs CreditAttribution: bvanmeurs commentedThis is not fixed at all. I downloaded the latest version and still get the errors:
SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'weight' at row 1
I regularly import nodes and am getting errors all over the place due to the weight module. It's simply unacceptable.
Comment #9
bvanmeurs CreditAttribution: bvanmeurs commentedP.S. it seems to be fixed in the dev version. Using that one now. I hope that it will be merged quickly to the release version!
Regards,
Bas
Comment #10
TechNikh CreditAttribution: TechNikh commenteddev version fixed my issue
Comment #12
bvanmeurs CreditAttribution: bvanmeurs commentedI updated to weight 2.1 but encountered this issue again. It only appears when you save a node programmatically which doesn't have a weight explicitly assigned to it, or has an empty value assigned to it. I thought this was fixed in 2.1, but I reviews the code and saw no changes in the _weight_set_weight function. Imho, in this function, there should be a check; either refusing to save the value to correct it to the default when it is incorrect. Right now, I get the following error on saving a general page node (which does not has weight enabled):
How about the following solution?
I hope you can fix this soon. I've been having this issue with the weight module some time now and have reverted to using 'old style' integer fields which is a shame as the idea behind your module is great.
Thanks!
Bas
Comment #13
bvanmeurs CreditAttribution: bvanmeurs commentedChanged the status to active, as this bug wasn't fixed.
Comment #14
davisbenCould you give an example of the code you're using that is causing the error?
Comment #15
davisbenI'm unable to reproduce this.
Comment #15.0
davisbenupdated with link to related issue
Comment #16
knalstaaf CreditAttribution: knalstaaf commentedI'm running into the same issue.
Cleared the weights, reset them, all to no avail.
If you manually set all the weights in the content overview to '1' for instance, it keeps this value for all the nodes. But having over 50 nodes, this is a tedious method. I tried to change the weight value in bulk, using Administration Views, but apparently AV doesn't recognize the weight field, eventhough it offers the field as a value to change. (I'm aware that AV doesn't play well with Weight (so far).)
I tried to move on to 7.x-3.x (since there's no 7.x-2.x-dev availabe), but I guess this is still in full development. I couldn't assign weight options to content types (did run the module updates).
Hopefully this information provides a clue to the issue. I'm not sure if this is of any importance, but there's a tilde in the url of the project we're working on (
domain.com/~project
). If more information is required, ask away.Comment #17
kenficara CreditAttribution: kenficara commentedThis is a related problem, or maybe the same problem -- I'm using 7.x-2.4 and have noticed that users are unable to set a weight of zero. Fixed this by changing the check in
_weight_set_weight
to check if$weight
is set, rather than if it is truthy:Comment #18
kenficara CreditAttribution: kenficara commentedComment #19
katannshaw CreditAttribution: katannshaw commented@kenficara: This was a pain. Patch #18 solved this issue for me. Thanks so much.
Comment #20
Christian DeLoach CreditAttribution: Christian DeLoach commentedPatch #18 solved this issue for me too. Thanks kenficara.
Comment #21
deggertsen CreditAttribution: deggertsen commentedThank you for #18. Very annoying problem, very simple fix. RTBC
Comment #22
davisbenThis was fixed with #2392401: Weight 0 not persistent.