I have a content types with 3 file fields, all of them can have an unlimited number of images. I need to make a view that returns the title of the content and the images name inside an array (I'm using amfphp with services). The problem is that when I add the relationship to the content field_pics fid I get as many duplicate nodes as the number of the images in the field:
EG:
[10] => stdClass Object
(
[nid] => 56
[node_title] => asd asd asd
[node_language] =>
[node_nid] => 56
)
[11] => stdClass Object
(
[nid] => 56
[node_title] => asd asd asd
[node_language] =>
[node_nid] => 56
)
This is the query:
SELECT node.nid AS nid, node.title AS node_title, node.language AS node_language, node.nid AS node_nid
FROM node node
LEFT JOIN content_field_colori node_data_field_colori ON node.vid = node_data_field_colori.vid
LEFT JOIN files files_node_data_field_colori ON node_data_field_colori.field_colori_fid = files_node_data_field_colori.fid
WHERE (node.status <> 0 OR (node.uid = ***CURRENT_USER*** AND ***CURRENT_USER*** <> 0) OR ***ADMINISTER_NODES*** = 1) AND (node.type in ('prodotto'))
ORDER BY node_nid ASC
I don't know how to fix this.
ANy help is appreciated.
Thanks
I think I understand what you're trying to do now. Unfortunately, Services's views support isn't all that great when it comes to CCK. There are a lot of different issues (e.g. one, two, three) with a lot of different patches and comments, but based on my understanding, to capture what you want is to not use relationships and to use the Node row style. If you use relationships, you get the output you're seeing, and if you use the Fields row style, the ImageField fields never load.
Related
Running drupal 7.22, I need to add an option to sort to a view - Content type Lecture which is associated with Curses.
In the Curse page I need to display the Lecture in a certain order.
The Lecture are dispayed in the following way
print views_embed_view('lecture_list_of_online_courses','block', $node->nid);
I tried the following simple solution -
added field 'my_wight' to the lecture content type
added values from 1 to 10 according to the necessary order.
add SORT CRITERIA to the lecture_list_of_online_courses view
result: the view displayed in a sort that seems to have nothing to do with the values I added to 'my_wight'
I've been working with drupal many times before, and did this sort of things more than once.
I can get whats wrong with this.
here is the resulting SQL query from the View -
SELECT node_field_data_field_oc_forum_reference.nid AS node_field_data_field_oc_forum_reference_nid, node_field_data_field_oc_forum_reference.title AS node_field_data_field_oc_forum_reference_title, node_field_data_field_oc_forum_reference.language AS node_field_data_field_oc_forum_reference_language, node_field_data_field_oc_forum_reference.type AS node_field_data_field_oc_forum_reference_type, node_field_data_field_oc_forum_reference.comment AS node_field_data_field_oc_forum_reference_comment, field_data_field_lecture_weight.field_lecture_weight_value AS field_data_field_lecture_weight_field_lecture_weight_value, 'node' AS field_data_body_node_entity_type
FROM
{node} node
LEFT JOIN {field_data_field_oc_forum_reference} field_data_field_oc_forum_reference ON node.nid = field_data_field_oc_forum_reference.entity_id AND (field_data_field_oc_forum_reference.entity_type = 'node' AND field_data_field_oc_forum_reference.deleted = '0')
INNER JOIN {node} node_field_data_field_oc_forum_reference ON field_data_field_oc_forum_reference.field_oc_forum_reference_nid = node_field_data_field_oc_forum_reference.nid
LEFT JOIN {field_data_field_lecture_weight} field_data_field_lecture_weight ON node.nid = field_data_field_lecture_weight.entity_id AND (field_data_field_lecture_weight.entity_type = 'node' AND field_data_field_lecture_weight.deleted = '0')
WHERE (( (node.nid = '175' ) )AND(( (node.status = '1') AND (node.type IN ('online_courses')) )))
ORDER BY field_data_field_lecture_weight_field_lecture_weight_value DESC
I cannot run this query - any idea why?
First - for the SQL to work you must remove '{' and '}' from the query
Second - When creating the SORT CRITERIA, u need to chose 'Relationship' in the settings of the SORT CRITERIA
I have a big issue today on my website using Drupal 7.22.
This issue appear on new node creation from an admin.
PDOException : SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '308' for key 'PRIMARY': INSERT INTO {node} (nid, vid, type, language, title, uid, status, created, changed, comment, promote, sticky, tnid, translate) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11, :db_insert_placeholder_12, :db_insert_placeholder_13); Array ( [:db_insert_placeholder_0] => 308 [:db_insert_placeholder_1] => 308 [:db_insert_placeholder_2] => evenements [:db_insert_placeholder_3] => fr [:db_insert_placeholder_4] => TEST [:db_insert_placeholder_5] => 1 [:db_insert_placeholder_6] => 0 [:db_insert_placeholder_7] => 1381931095 [:db_insert_placeholder_8] => 1381931095 [:db_insert_placeholder_9] => 1 [:db_insert_placeholder_10] => 0 [:db_insert_placeholder_11] => 0 [:db_insert_placeholder_12] => 0 [:db_insert_placeholder_13] => 0 ) dans drupal_write_record() (ligne 7136 dans /var/www/carioca/includes/common.inc).
I have checked the database and the last node id is 294.
Does anyone have an idea how to solve this issue ?
Thanks for your help.
If you have a PhpMyAdmin for your Database, have a look at the tables: node & node_revision. Could be that you have different indexes in there and causes that the id cannot be inserted.
Your issue is not that there is already an entry in the DB but that node & node_revision (or other table) has different state as the other tables does. The data within your DB seems to not be consistent.
Are you having custom table handles within your modules? Fix the Id issues and use the node_load or user_load Drupal API functions instead of custom DB calls.
If you are on Drupal 6 have a look into the node_counter table where there could be a older value.
When executing the following mysql query, do you have a result?
SELECT * FROM node WHERE nid = 308;
I am trying to create "previous/next node" navigation on my nodes in order to show 2 previous and 2 following nodes in the term currently being viewed. Here is the code that displays 2 prev and 2 next nodes, but it is not taxonomy aware, i. e. it sorts nodes according to their IDs:
Prev/Next node navigation with a thumbnail in a full node
If I add a node in the term after some time, it will display this node as the last one, not as a "neighbour" of a node uploaded e.g. 3 months ago.
I have tried with "n.title", but it doesn't change anything. Ideally, it should order them either by titles or url aliases.
Thank you in advance!
it's not querying the taxonomy tables in the database query. You probably want to add a variable to the function as such dad_prev_next($current_node = NULL, $op = 'p', $tid) to pass it the term ID and then add that to your query through an inner join
SELECT n.nid, n.title
FROM {node} n
INNER JOIN {taxonomy_index} t
ON n.nid = t.nid
WHERE n.nid $sql_op :nid
AND t.tid = :tid
AND type IN ('photos')
AND status = 1
ORDER BY n.nid $order
LIMIT 1
I think that should be pretty close, then just pass that at the end of db_query db_query($sql, array(':nid' => $current_node -> nid, ':tid' => $tid));
Newer version of Previous/Next module has multiple options for sorting prev/next nodes. You can use the workaround to get thumbnails too:
http://drupal.org/project/prev_next
http://drupal.org/node/1790290
print_r($sql);
echo "\n";
print_r($sql_params);
$result = db_query($sql, $sql_params); // Error happening here
Output:
select SQL_CALC_FOUND_ROWS * from rocdocs_database_1318520218 where 1=1 order by ? ? limit ?, ?
Array
(
[0] => c5
[1] => desc
[2] => 0
[3] => 50
)
According to the documentation I can used ordered parameters by using an array and ? marks, but it seems to be erroring. Any ways to debug this? I have installed devel, but it doesn't show the query.
You can't use placeholders for anything that is "sql structure" like sort definitions, table/column names and so on. This is impossible.
If you need dynamic order by definitions, use db_select() and then orderBy(). Make sure to validate what you pass in through that.
Basically we wanted to move a portion of our drupal 6 site to our drupal 7 build. Using the migrate module. While migrating 155 nodes with their comments and taxonomy(2 vocabs, one is fixed the other is comma seperated) the last 30 fail giving me this error:
291 Error PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'tid' at row 1: INSERT INTO {taxonomy_index} (nid, tid, sticky, created) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3); Array ( [:db_insert_placeholder_0] => 3057 [:db_insert_placeholder_1] => [:db_insert_placeholder_2] => 0 [:db_insert_placeholder_3] => 1282050381 ) in taxonomy_field_insert() (line 1675 of /u01/facebase/drupal-7.0/modules/taxonomy/taxonomy.module).
291 Error SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'tid' at row 1
I'm migrating my terms using this query:
$query = db_select("$this->_db.term_data", 'td')
->fields('td', array('tid', 'name', 'weight'))
->condition('v.vid', 7);
$query->innerJoin("$this->_db.vocabulary", 'v', 'td.vid=v.vid');
I do this for 2 vocabularies, and then I map just the name, format, and weight. Then i'm using this query while migrating the nodes:
$query = db_select("$this->_db.node", 'n')
->fields('n', array('nid', 'vid', 'type', 'title', 'uid', 'status', 'created', 'changed', 'comment'))
->fields('tn', array('tid'))
->fields('nr', array('title', 'body', 'teaser'))
->condition('n.type', 'dev_content');
$query->leftJoin("$this->_db.term_node", 'tn', 'tn.vid =n.vid');
$query->leftJoin("$this->_db.node_revisions", 'nr', 'nr.vid = n.vid');
$query->addExpression('GROUP_CONCAT(DISTINCT tn.tid)', 'term_list');
$query->groupBy('n.nid');
Then i'm mapping the term_list for each vocabulary like this:
$this->addFieldMapping('field_dev_tags', 'term_list')
->separator(',')
->sourceMigration('DevCenterTerm')
->arguments(array('source_type' => 'tid'));
$this->addFieldMapping('field_dev_category', 'term_list')
->separator(',')
->sourceMigration('DevCenterTermPrep')
->arguments(array('source_type' => 'tid'));
I know this is happening due to the terms, as when i don't map the term_list all the nodes get created, but thats about it. Any ideas?
Is this an issue with those nodes not having a taxonomy assigned to them? If this is the case, try adding a default value to the taxonomy field mapping.
$this->addFieldMapping('field_dev_category', 'term_list')
->separator(',')
->sourceMigration('DevCenterTermPrep')
->arguments(array('source_type' => 'tid'))->defaultValue(12);
In the beer.inc example, this is documented in the comments:
You can also use both together - if a default value is provided in
addition to a source field, the default value will be applied to any
rows where the source field is empty or NULL.