modifying primary key manually

5 views
Skip to first unread message

rip_pit

unread,
May 31, 2009, 12:46:11 PM5/31/09
to Php Object Generator
I think there were already subject about changing the primary key from
the pog objects, but here is a real case:

As everytime i used POG, my tables were already existing and used into
projects, so i already have a given primary key name that i cannot
modify.

Here's the real case:
My table name is : entreprises
The PK (already existing) is : id_entreprise
The PK generated by pog is : entreprisesId ("ObjectName"+Id)

I want the PK to be mine and not "ObjectName"+Id so i edited manually
Entreprises.class.php and changed the reference from the pog PK to my
already existing PK. (i replaced all (POGPK)entreprisesId by (MYPK)
id_entreprise)

Everything was fine except when doing check db setup test where i
receive errors like this:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL
result resource in D:\weblocal\www\sites_ag2i\gpecpog\objects
\class.database.php on line 52
......
CHECKED 1 OBJECT(S). FOUND 1 ERROR(S):
---------------------------------------------------
ERROR: GetList() :sizeof(list) != \$limit\n
Query failed: select * from `entreprises` where `entreprisesId` >=
'1' AND `entreprisesId` <= '3' order by entreprisesId desc LIMIT 2
------------------------------------------
You can see, it doesn't use MyPK for doing tests but POGPK ...

I can found that this error comes from /setup/rpc.php where the PK is
generated at line 184:
$instanceList = $instance->GetList(array(array(strtolower
($objectName)."Id",">",0)), strtolower($objectName)."Id", false,
$sqlLimit);
Instead of using MyPK, it use a PK using ObjectName . "Id", which give
"entreprises"."Id", and not the one i need that is "id_entreprises"

Here was the thing i wanted to point out.

I will edit and change this line to feat MyPK. (not tested yet)


Maybe POG admins could reflect this case in a future update.

BTW, POG is a great thing and a big help. Thank you to all person
making pog existing!
thanx for reading!

rip_pit

unread,
May 31, 2009, 1:10:56 PM5/31/09
to Php Object Generator
After doing manual changes, i found that there were a lot of other
calls to POG PK like (strtolower($ObjectName)."Id") in many other
setup files, like
setup_misc.php, index.php, rpc.php.

i succeed in changing all of them in all files but i was a hard job ^^

It would be really usefull to be able to modify PK when using POG.
Thanx.

Kosta Kontos

unread,
Jul 5, 2009, 3:42:18 PM7/5/09
to Php Object Generator
On May 31, 5:10 pm, rip_pit <rotinpain....@gmail.com> wrote:
> It would be really usefull to be able to modify PK when using POG.
> Thanx.

Yes I second that.

Could the POG team please include a field in your object generation
form that allows us to specify the names of all keys (both primary and
foreign)?

The primary key input text field is straight forward, however foreign
keys will be tricky. Perhaps a clever Ajax input text field popup when
we select the attribute's type to be CHILD / PARENT / SIBLING, in
which we can specify the foreign key's name.

Thanks for a great product,
Kosta.

Mendu

unread,
Jul 25, 2009, 11:27:12 AM7/25/09
to Php Object Generator
Hi,I want the PK to be mine and not "ObjectName"+Id too and i will
edit all. if you have get it succesfully, please write it. at this
time i only have problems with delete list.

$className = get_class($object);
//Mendu parcheando problema Primary Key original
if (strtolower($className)=='members'){
$objectList = $object->GetList(array(array("ID_MEMBER", ">", 0)));
}else{ //lo que hace normalmente
$objectList = $object->GetList(array(array(strtolower
($className)."Id", ">", 0)));
}
next i will try to do a generic procedure for all my objects. i will
continue saw it here

sorry for my bad english.i speak spanish

thanks a lot

Mendu

unread,
Jul 26, 2009, 9:59:33 AM7/26/09
to Php Object Generator
hi, at this time i succeed in changing all and i don´t have any
errors. when i push the button "pog me up" i see:

Initializing POG Setup....OK!
File Structure....OK!
Configuration Info....OK!

Storage Status
Aligning [members] with table 'members'....OK!

POG Essentials
[members]
Save()....OK!
SaveNew()....OK!
Delete()....OK!
GetList()
Limit....OK!
Sorting....OK!
DeleteList()....OK!
Optimizing....OK!

POG Relations PreRequisites
[members]
Is single (OK)

POG Relations
[members]

CHECKED 1 OBJECT(S). FOUND 0 ERROR(S). HURRAY!

push proceed

Next i go to the manage object´s screen and it seems that all is Well
done but i can´t see any object and i can´t see the "add object"
option.

i will continue with this subject.

sorry i´m learning to write english. thanks

Mendu

unread,
Jul 26, 2009, 12:38:15 PM7/26/09
to Php Object Generator
well, i can´t use the setup aplication but when i started to do the
first test in my aplication:

echo count($listamember);

then i can see on the screen: 1 and this is the one record that i have
in my bd.

but at this time i cant print the object propertys

Crispytwo

unread,
Jul 27, 2009, 12:33:27 AM7/27/09
to Php Object Generator
try to print it after you do a count like this:

echo var_export($listamember,true);

this should show the contents

Mario

unread,
Jul 27, 2009, 3:55:04 PM7/27/09
to Php-Object...@googlegroups.com
hi everybody, hope you don't mind if I answer him in spanish as its easier for Mendi to understand what I am saying.

Spanish:

Mendi, es mucho más fácil ejecutar un simple reemplazo del identificador que genera automáticamente
en el archivo generado. Es decir, si tu clase generada con POG se llama "members" y quieres que la
clave principal sea id, en minúsculas por ejemplo (tanto a nivel de objeto como de base de datos) reemplaza
en el archivo que te genera POG "membersId" por "id" (sin ser sensible a mayúsculas el reemplazo, de tal forma
que reemplace tanto los campos de bbdd como de la clase php. Yo lo hago a menudo para reescribir una aplicación
que no era orientada a objetos y que ya tenía su mapeado a base de datos con identificados llamados id, en vez
de los que genera POG.

Si tienes alguna duda vuelve a consultar, pero es bien sencillo. El único incoveniente es que cuando uses una
url POG para volver a generar el código tendrás que volver a reemplazar el nombre del campo para que tu código
funcione.

Suerte.

English summary:

Mendi it's easier if you just replace the string of the generated id with what the name you want it to have in
the POG generated code. What I mean is, for example, just imagine your class generated with POG is named "members"
and what you want is that the id field has name "id" instead of "membersId", (so in the database table so as a class field),
then just replace the string "membersId" with "id" in the generated file (doing a not case-sensitive replace). Doing so all
methods will work OK (Save, GetList, Get and so).

Have a nice day.



2009/7/27 Crispytwo <marks...@gmail.com>



--
The most likely way for the world to be destroyed, most experts agree, is by accident.
That's where we come in; we're computer professionals.
We cause accidents.
(Nathaniel Borenstein)

Rafael Ruiz Menduiña

unread,
Jul 28, 2009, 2:52:42 AM7/28/09
to Php-Object...@googlegroups.com
Gracias Mario pero el verdadero problema que trato de solucionar es el de no tener que tocar la base de datos para nada, no modificarla en lo mas minimo y poder hacer una aplicacion limpia con la bd del cliente que es usada por su propia aplicacion. Yo solo deberia leer de su bd y despues si en mi tabla nueva hacer lo que quisiera. yo programo en .net y utilizo hibernate y lo mas comun es encontrarte una bd existente de un cliente que no puedes modificar para que la aplicacion que ya tenia éste siga funcionando bien, ademas que considero una buena practica el llegar y no tener que alterar una bd cliente existente. Otra cosa es que si el nombre de las columnas estan en mayusculas, pog lo pone todo en minusculas y esto es otro problema. 

siento no traducir a ingles ahora.
Muchas gracias.



2009/7/27 Mario <lok...@gmail.com>
Reply all
Reply to author
Forward
0 new messages