Hello Fabian,

Are you sure that you have a HABTM relationship or a belongsTo? In
your query there is a field 'user.verse_id', that is not needed. For a
habtm, there should be three tables in your db:
--
USERS:
======
id, name, ...
VERSES:
=======
id, name, ...
USERS_VERSES:
==============
id, user_id, verse_id

the last one is the join table, that is required for habtm. A left
join is done by default when you do the following in the users
controller (assumed you set the HABTM-relationship in the user model):

--
$params['conditions'] = array('User.id' => 1);
$params['limit'] = 10;
$res = $this->User->find('all', $params)
--

$res will be filled with the user data where User.id = 1 and the the
verses belonging to that user, like:
array(
    ['User'] => array(
        ['id'] => 1
        ['name'] => ...
        ....
    ['Verse'] => array(
        ....
);

In addition you could add the Containable Behaviour (http://
book.cakephp.org/view/474/Containable) to cut down the resulting data
to what you need (in case you have more than one relationship set up
in the Users model).

hope that helps,
harpax

On 28 Apr., 12:14, Fabian <fabian.pet...@gmail.com> wrote:
> Hey,
> I'm so happy I've found this group. Maybe someone can help me with my
> problems here (I'm a beginner in Cakephp). Sorry for my bad english by
> the way.
>
> Ok I've got two Models in HABTM relation: verses and users. in my
> controller action i want to get some specific verses (for example: the
> first ten verses) and something like a left join to the users table,
> so i can see whether the logged in user is assigned to any of them.
> BUT i don't want to show any other users and I don't want to have only
> the verses the user is assigned to.
>
> This would mean, Someone reads some verses and beside some of them is
> a little note "you are assigned to these verses"....(maybe there is an
> even easier solution for this?)
>
> In MySQL this Query works perfectly:
> SELECT * FROM verses LEFT JOIN (SELECT * FROM users_verses WHERE
> user_id = 1) AS user ON verses.id = user.verse_id LIMIT 10
>
> the subquery only searches users_verses for user 1 and in left joining
> the verses table some of the ten verses will have the user assigned to
> it and some are simply nulled.
>
> how can I get the same effect with cakephp?
>
> THANK YOU so much for you help
> Fabian
--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to