There's (at least) two ways of designing auxiliary tables in a
database like mysql. Auxiliary table is a table that maps certain
codes to text and more meaningful information, and are not constantly
updated. For instance, I have a table "costumer" which have a field
"status", which can have values from 0-5. The name of each status is
stored in a table named "status" (some prefer "aux_status"). In some
databases, you may have 5-10 auxiliary tables. In cakephp, I would
have then one model for each auxiliary table.
Other way of doing that is to create a table named, ahem, "table" with
3 fields: id, table_name, name, and store all data (which would be
stored in many auxiliary tables) in just this table.
Putting aside the merits and demerits of that particular approach
(let's say, for the sake of argument, that it's a legacy database), I
would like to know how to make BelongsTo work.
That's the auxiliary table in question:
create database Status
(
id integer auto_increment
banco_id integer, -- that's table_id
column_name varchar(255),
value integer, -- the value, or id, or code
description varchar(255) -- corresponding to the value above
)
That worked fine in Cake1.1 ($c is the column_name)
'Status' => array(
'className' => 'CamposMapeados',
'foreignKey' => '',
'conditions' => 'Status.banco_id = {$id} AND Status.column_name =
\"{$c}\" AND Status.value = User.{$c}'
)
as cake create just one query with JOINs. However in Cake1.2 the query
parser splits the queries, and the last part Status.value = User.{$c}
yields error, as it's only querying the "Status" table.
I could think of splitting the all-in-one auxiliary table into many
others, but I don't want to work. Do anybody have a clue on how to
solve this problem?
Thanks and happy new year to everybody!
Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
No comments:
Post a Comment