[development] node_load using cck fields

Lluís Forns enboig at gmail.com
Tue Mar 22 16:59:07 UTC 2011


$field = content_fields('field_date');
$db_info = content_database_info($field);

I will try to build a query which gets if it need to add joins,
etc...; so if database schema is changed it will also change.

2011/3/22 Guillaume ! <guillaume at resist.ca>:
> Hash: SHA256
> That will work in most cases, but if you ever re-use one of the fields
> of the date content type with another content type, the field will be
> moved to its own table (content_field_date). The safe way is really of
> using views, or node_load, but there are obvious scalability issues
> with foreach($a = node_load($nid++)), because they are really
> independant of the content_type current structure. See
> http://groups.drupal.org/node/10129 for more details.
> Guillaume !
> On 11-03-22 09:47 AM, Steve Edwards wrote:
>> Here is the magic incantation:
>> http://drewish.com/content/2010/06/correctly_accessing_cck_fields_in_sql_queries
> Steve
>> On Mar 22, 2011, at 9:45 AM, larry at garfieldtech.com wrote:
>>> You can only load nodes in D6 individually by ID. However, you
>>> can run raw SQL queries to find nodes meeting certain criteria,
>>> then run node_load() on those IDs. I forget the functions off
>>> hand but there is a magic incantation to get the right field
>>> column info and build a query string yourself.
>>> That said, if you're going to be displaying the node(s) then just
>>> use Views. It will take much less time and be much more stable,
>>> and offer better theming options.
>>> In Drupal 7, you'd either use Views or the new EntityFieldQuery.
>>> --Larry Garfield
>>> On 3/22/11 11:40 AM, Lluís Forns wrote:
>>>> I want to load a node using cck fields instead of nid or core
>>>> fields.
>>>> Is there a "no-sql" way of doing this? I have read that maybe I
>>>> could achieve it using views, but I think it would be an
>>>> overkill.
>>>> What I want to achieve is something like this:
>>>> $inscripcio = node_load(array( 'type' => 'inscripcio',
>>>> 'field_alumne' => $nid_alumne, 'field_convocatoria' =>
>>>> $nid_convocatoria, ));
>>>> any hint?
>>>> If I could get which tables use a cck type and how to join
>>>> them, maybe I could code a "generic" way to do this, so if
>>>> cck-type is changed, there is no problem.
> Version: GnuPG v1.4.10 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
> sZqEYnFky2cwnU8FAw5gcneDipc6NlnrzhQFMvPGP9f0r5K9RmRpGkre5VoChXuR
> Tkw87GyOCKS3NADOOWjI4bicas8m6CDFJHpRSpQRtWgLMne6kNa6P3+3fO0zMXki
> 4+bKxDaoYj8+bAIRNpOuO2VBE1pW7fG9Bsthte6AkCh2VFtqKvJfJ8VG0qMko2sU
> c3QJbgefKpYtwOXroLPvk4aY4wdnTRPRC35gDdR4Y2TgPbPossr7u/l6NGbGB2O7
> 3Dff8RumNvL13rscpamzjNIHN4f8aDZc4YrtEzLqlsvJOk23aYBygayXiTsir5RH
> ICek+tje4St28Awf5LiRS69WqQ8fuyLgu6+3h+sdfNcBvej43KCM9BJOQ7triECx
> q8Pl4X//lAem2SP+Toy0tNi/iVUdEsb1Q2XzyxY84MvQZA/rYcxhvjLLh0aJKa7f
> cH3FxXzxSNM0G/YhC7V7EEC/UqeTWyhE5HAq2LPqtVj0eML1CHLeSsMqulCzLO2D
> avT9VfSlsMrkslD0O/vAQYaeuN5575vVVVnFvK6KEd7wLmLa7fthxqurseYEYCgt
> DGTE2d5op/4l3o5/H0D6
> =a9c0

*Les normes hi són perquè hi pensis abans de saltar-te-les
*La vida és com una taronja, què esperes a exprimir-la?
*Si creus que l'educació és cara, prova la ignorància.
*La vida és com una moneda, la pots gastar en el que vulguis però
només una vegada.
*Abans d'imprimir aquest missatge, pensa en el medi ambient.

More information about the development mailing list