0

I'm not familiar with drupal. Using raw SQL, I'd like to extract votes given to each node, but I wonder how vote_rating is related to node?

I see that the votes are stored in field_vote_rating of this table:

mysql> DESCRIBE `field_data_field_vote`;
+-------------------+------------------+------+-----+---------+-------+
| Field             | Type             | Null | Key | Default | Extra |
+-------------------+------------------+------+-----+---------+-------+
| entity_type       | varchar(128)     | NO   | PRI |         |       |
| bundle            | varchar(128)     | NO   | MUL |         |       |
| deleted           | tinyint(4)       | NO   | PRI | 0       |       |
| entity_id         | int(10) unsigned | NO   | PRI | NULL    |       |
| revision_id       | int(10) unsigned | YES  | MUL | NULL    |       |
| language          | varchar(32)      | NO   | PRI |         |       |
| delta             | int(10) unsigned | NO   | PRI | NULL    |       |
| field_vote_rating | int(10) unsigned | YES  |     | NULL    |       |
| field_vote_target | int(10) unsigned | YES  |     | NULL    |       |
+-------------------+------------------+------+-----+---------+-------+

I'm aware of Drupal's database structure schema, which looks like so:

enter image description here

But I cannot figure out how to make a query to connect them.

My question: How to make a raw SQL query to get the node/node_votes pairs?

Any suggestions?

  • Are you asking about how the SQL should look like, or about some kind of tool/interface integrated with Drupal to write/run the SQL query you already have in mind? Maybe something else? Please EDIT your question to clarify that, OK? – Pierre.Vriens Nov 4 '15 at 7:12
  • @Pierre.Vriens My question is about how to make a raw sql query to get the node/node_votes pairs. I've mentioned this in the first line but made it more explicit nonetheless. – Jand Nov 4 '15 at 10:29
  • 1
    I've tried to further refine your question (hope I did not introduce any errors in what you really want to ask). Please review and correct/enhance it where needed, OK? – Pierre.Vriens Nov 4 '15 at 10:43
1

Try this query:

SELECT field_vote_rating from field_data_field_vote
WHERE entity_type = 'node' AND entity_id = $nid;

You can use the database api to create SQL Queries

  • This is not a valid sql query. – Jand Nov 4 '15 at 10:31
  • 2
    @Jand To be fair, anyone who's used PHP before will understand what that means. In case you're not in that group, it's a php variable which the op is using to indicate a placeholder for the proper variable. Replace that with the node id you're interested in, or remove that clause if you want to filter on all nodes – Clive Nov 4 '15 at 10:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.