[development] Accessing CCK field data (single, multiple, or shared) from another module
Karen Stevenson
karen at elderweb.com
Fri Mar 23 12:48:42 UTC 2007
To find the right table for a field for a SQL query, use the API, like this:
$db_info = content_database_info($field);
$table = $db_info['table'];
That will always return the right table for the requested field.
$field needs to be the complete field array, not just the field name, so if you only have the field name, you would do:
$field = content_fields(my_field_name);
$db_info = content_database_info($field);
$table = $db_info['table'];
content_database_info($field) also contains info about the columns declared by the field so you know what field names to use in a SQL query. It returns an array that looks like:
Array (
[table] => content_type_story
[columns] => Array (
[value] => Array (
[type] => varchar
[length] => 50
[not null] => 1
[default] => ''
[sortable] => 1
[column] => field_phone_value
)
[value2] => Array (
[type] => int
[length] => 10
[unsigned] => 1
[not null] => 1
[default] => 0
[column] => field_phone_type
)
)
)
----- Original Message ----
From: Rob Barreca <rob at electronicinsight.com>
To: development at drupal.org
Sent: Thursday, March 22, 2007 7:55:31 PM
Subject: Re: [development] Accessing CCK field data (single, multiple, or shared) from another module
>
> Is there a function for getting the data that you can just give a node
> type and a field name and it handles the rest?
This is something I've just run into as well. I have a hardcoded to
query the DB for the multiple field table, but have a TODO in there to
find the right API call.
Rob Roy Barreca
Founder and COO
Electronic Insight Corporation
http://www.electronicinsight.com
rob at electronicinsight.com
Benjamin Melançon wrote:
> Gracious developers, CCK people especially...
>
> I wrote an access control module that works with the node relativity
> module to cascade permissions to all nodes lower in a hierarchy. I
> hard-coded a query for a userreference field on a custom content type
> as one way to give a user access to a node (and its descendants).
>
> In generalizing this, the current stumbling block is the way CCK
> stores single instances in the content data table and shared instances
> of a field in a separate table.
>
> Is there a function for getting the data that you can just give a node
> type and a field name and it handles the rest?
>
> Or is there a place to check what the case is for a particular field?
> (Even a "column_exists()" function would do it for me, but haven't
> found one in PHP...)
>
> It's being developed in Drupal 5 and fixing this (as well as saving
> explicitly permitted users when creating a new node) is all that's
> needed for posting the project for general use.
>
> Many thanks,
>
> ben
>
> Agaric Design Collective
> Open Source Web Development
> http://AgaricDesign.com/
>
> People Who Give a Damn
> building the infrastructure of a network for everyone
> http://pwgd.org/
More information about the development
mailing list