I have two tables I want to link together, but the association is a
bit more complicated than it normally would be. One of the tables
(users) is built specifically for cake, another is a table from a read-
only database (salespeople). User.username = Salespeople.email (or xxx
in [email protected]).

Users can have multiple Salespeople
Salespeople will have one User

So I have Users hasMany Salesperson
Salespeople belongTo User

In the hasMany association, you can assign the finderQuery condition
to have a custom association. So I set that to get the all the
Salespeople records with an email (minus @site.com) that matches
User.username.

The belongsTo association doesn't seem to provide the finderQuery
condition, according to the documentation. I was looking around in the
api to see if it really did but was just left out of the documentation
but I couldn't find it. Furthermore, I'm getting errors with it in, so
I assume it isn't allowed in a belongsTo association.

So my question is has anyone done something similar or can help point
me in the right direction? There really weren't any examples of using
finderQuery in the documentation either, so I sort of guessed on the
format the query itself should take.

For completeness, my finderQuery in the User model is (using MS SQL
Server):
SELECT s.*
FROM users u
INNER JOIN salespeople s ON rtrim(replace(left(s.email, charindex('@',
s.email)), '@', ' ')) = u.username
where u.id = $this->id

That would be the correct format for finderQuery to work, correct?

Thanks for any help anyone can provide.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to