tags:

views:

129

answers:

1

convert following query into cakephpquery.

"SELECT * FROM user1.user_favourites,esl.esl_lyrics
WHERE
    esl_lyrics.id=user_favourites.fav_recordID
    AND user_favourites.fav_userID=".$user_id."
    AND user_favourites.fav_widgetID=$wid_id";

Models files are esl.php and userFavourite.php DB are user1 and esl. DB tables are user_favourites in user1 and esl_lyrics in esl DB.

plz give details.what changes are do in esl.php and userFavourite.php

please Help me...

A: 

It will be difficult to determine what to write until you can provide a data map for the various IDs you are using. Since you are not conforming to standards in your SQL, the fields are all named different in the various tables. But here is what I understand so far:

esl_lyrics.id = user_favorites.fav_recordID

From your description there are two models. So you will need to make sure you have relationships between the two. This will require that you determine if it is belongsTo, hasOne, hasMany, etc. It also appears you are using multiple databases (schemas), so you will need to configure the database.php so that you can access each one.

Once everything is configured you should be able to access the data as:

$this->Model1->Model2->find('all', array('conditions' => array('Model1.id' => 'Model2.id', 'Model2.user_id' => $user_id, 'Model2.widgetID' => $wid_id)));

It will return an array with the data from both models. But until you can share what your models look like and a mapping of ids etc., this will be as good of an answer as you will get.

cdburgess