|
From: Germán <ger...@ya...> - 2011-10-15 00:34:08
|
Hello, and thanks for the info about the "association bugs".
I was bumping into the same problem of the foreign keys. Then I found
your work on svn. But when I tried it returned me a warning telling me
the name of the association had to end with '_id'. And indeed, the name
ended with '_id', then I dared to modify your code and I was able to
make it work (was only a little error).
Here is the patch.
--- generate_code_sql.c (revisión: 7)
+++ generate_code_sql.c (copia de trabajo)
@@ -156,9 +156,8 @@
*/
- char tail[4];
const char *fk_col = temp->name;
- strncpy(tail, fk_col+sizeof(fk_col)-2, 3);
+ const char *tail=&fk_col[strlen(fk_col)-3];
if(!strcmp("_id", tail)){
fk_col = "id";
}
Warning: Never use sizeof() to take care of the length of an string.
If applied to a pointer is going to return the size it occupies in
memory the pointer, usually will get value 4 for 32-bit machines.
Therefore, always use strlen. Be careful also to put the null
terminator for strings. Anyway, here you have an alternative way to cut
the tail of a string.
Greetings from Argentina. (That explains my poor English)
--
Germán <ger...@ya...>
|