Wednesday, April 28, 2010

Re: how to add a relationship whit other key different to the PK

You can set foreign_key to false and instead use the condition of the
relationship. This is usually used for things like User.active => true
and simple things like that but I think it can be used for your
purpose.

COme to think of it, I may be wrong. I vaguely recall an RC for
Cake1.2 causing problems when the condition is not an array... and I
think you might need a string contition.


On Apr 28, 12:54 am, Manolet Gmail <mano...@gmail.com> wrote:
> Hi, i have this tables:
>
> Software
> Reviews
> Mirror
> Requirements
> Published
>
> Now, this is the relations:
>
> Software Has Many Reviews
> Software Has Many Mirrors
> Software HABTM Requirements
>
> Works fine.
>
> The problem is that i need to resume the tables to get a better response
> from mysql, the reviews tables have text fields and are classified by
> language, so, for the public site i do a Published table for each language,
> i mean: language_en language_es language_fr and load the data automatically
> into that tables...
>
> The Published table is a merge of the Software and Review Table. The PK of
> Published table is 'id', and is the same number of the reviews table.
>
> I want to establish this relationship: Published.software_id (not the PK)
> Has Many Mirrors.software_id
>
> The key has a Unique index, the problem is that aparently i can use the
> foreign_key attribute when declaring the relationship to set the Mirror
> model field, but i cant set the field that i want to use on the Published
> model, it uses the PK by default.
>
> Is there a way to force it to use other key different to the PK for the
> queries?
>
> Currently im using afterFind function and works okey, but dont allows me to
> use "contain" or "fields".
>
> Hope you can understand me and help me
>
> thanks for you time,
>
> Manolo
>
> Check out the new CakePHP Questions sitehttp://cakeqs.organd 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 athttp://groups.google.com/group/cake-php?hl=en

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: