Bienvenido(a) a Proyecto Script

Hola!!!

Este es un buen lugar donde buscar las respuestas a tus dudas sobre "Programación", "Lenguajes", "Linux", "Electrónica", etc.

Suele ser difícil buscar en la red y encontrar respuestas claras y en español a muchas preguntas sobre estos temas, así que aquí tienes un buen lugar para iniciar.

Quieres ser parte de esto, solo ¡regístrate!

lunes, 8 de diciembre de 2008

Tabla simulando un arbol

Seguramente se ha presentado el caso donde tiene una tabla a nivel base de datos que guarda la información de una entidad que tiene un comportamiento de árbol, peensando un ejemplo práctico tenemos una tabla de Categorias la cual esta construida por el siguiente script:

   1 CREATE TABLE categories (
   2   id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
   3   nombre VARCHAR(20) NOT NULL,
   4   parent_id BIGINT NULL
   5 );


De esta manera podriamos tener lo siguiente:

  • General de División
    • General de Brigada
      • General Brigadrier


Y visto como una tabla tendrías:

id |        nombre       | parent_id
------------------------------------
 1 | General de División |   null
 2 | General de Brigada  |     1
 3 | General Brigadier   |     2


Vayamos al código...
Existe una funcion llamada "acts_as_tree" la cual nos ayuda con ese comportamiento, es importante hacer la aclaración que hasta la versión 1.x de Rails (mas específicamente en ActiveRecord) era parte de ésta, pero apartir de la versión 2.x, ésta fue seprada para convertirse en un plugin.

La instalación del plugin es muy sencilla, basta con ejecutar la siguiente linea:

script/plugin install acts_as_tree


Una vez hecho esto, podemos ir a nuestra clase model "Categoria":

   1 class Categoria < ActiveRecord::Base
   2   acts_as_tree :order => 'parent_id'
   3 end


De esta manera tenemos los isguientes metodos disponibles para aprovechar mucho mejor el comportamiento en arbol:

MétodoDescripcion
childrendevuelve todos los hijos inmediatos
parentdevuelve el padre (objeto inmediato)
siblingsdevuelve todos los hijos del mismo padre (hermanos)
self_and_siblingsdevuelve todos los hermanos incluyéndome
ancestorsdevuelve todos los objetos padre hasta llegar a la raiz (padre, abuelo, etc)
rootdevuelve el objeto raiz de la jerarquía


Digg!

viernes, 5 de diciembre de 2008

Problems compiling app-text/poppler-bindings-0.8.7

Hace algunos días trataba de compilar el paquete "app-text/poppler-bindings-0.8.7" pero me arrojaba el siguiente error en la compilación:

0001 neobalam proyectos # emerge -q1 =app-text/poppler-bindings-0.8.7
0002 >>> Verifying ebuild Manifests...
0003
0004 >>> Emerging (1 of 1) app-text/poppler-bindings-0.8.7 to /
0005 * Applying poppler-0.6-bindings.patch ... [ ok ]
0006 * Running eautoreconf in '/var/tmp/portage/app-text/poppler-bindings-0.8.7/work/poppler-0.8.7' ...
0007 ...
0008 checking for Qt headers... /usr/qt/3/include
0009 checking for Qt libraries... /usr/qt/3/lib
0010 checking if Qt needs -pthread... no
0011 checking for POPPLER_QT4... configure: error: Package requirements (QtCore >= 4.1.0 QtGui >= 4.1.0 QtXml >= 4.1.0 QtTest >= 4.1.0) were not met:
0012
0013 No package 'QtGui' found
0014
0015 Consider adjusting the PKG_CONFIG_PATH environment variable if you
0016 installed software in a non-standard prefix.
0017
0018 Alternatively, you may set the environment variables POPPLER_QT4_CFLAGS
0019 and POPPLER_QT4_LIBS to avoid the need to call pkg-config.
0020 See the pkg-config man page for more details.
0021
0022
0023 !!! Please attach the following file when seeking support:
0024 !!! /var/tmp/portage/app-text/poppler-bindings-0.8.7/work/poppler-0.8.7/config.log
0025 *
0026 * ERROR: app-text/poppler-bindings-0.8.7 failed.
0027 * Call stack:
0028 * ebuild.sh, line 49: Called src_compile
0029 * environment, line 2536: Called econf 'src_compile' 'src_compile' '--enable-cairo-output' '--enable-poppler-glib'
0030 * ebuild.sh, line 519: Called die
0031 * The specific snippet of code:
0032 * die "econf failed"
0033 * The die message:
0034 * econf failed
0035 *
0036 * If you need support, post the topmost build error, and the call stack if relevant.
0037 * A complete build log is located at '/var/tmp/portage/app-text/poppler-bindings-0.8.7/temp/build.log'.
0038 * The ebuild environment file is located at '/var/tmp/portage/app-text/poppler-bindings-0.8.7/temp/environment'.
0039 *
0040
0041 * Messages for package app-text/poppler-bindings-0.8.7:


Cabe mencionar que usaba el administrador "Portage" (para los que no sepan algo como el "apt-get", "yast", etc, a diferencia que este descara el código fuente y lo compila).

Por fin pude compilar ese paquete, basta con incluir en la compulacion qt-4 y poppler-bindings en la misma llamada de emerge-

Digg!