If you need to include another table, use the include directive
$posts =& $this->Post->find('all', array(
'conditions' => array('id=?', $id)
'include' => 'author'
));
Then you get all the author table's fields. Of course your models for posts and authors must have relationships setup like:
class Post extends ActiveRecord {
var $has_many = array(
'Authors' => array(
'dependent' => 'destroy'
));
}
class Author extends ActiveRecord {
var $belongs_to = array(
'Post'
);
}
The important thing to keep in mind with what you were trying is that you were using the findBySQL() method on the $Post model. Therefore you will only get fields back from the Post model.
Are you aware of AkDbAdapter methods available on active records at ->db or by getting an adapter instance using Ak::db()?
select
selectOne
selectValue
selectValues
Ah, figured it out. This is way cool!
Here is an example. FYI I was able to do inner joins on other tables as well. This is pretty much a free-for-all query.
This example is run in a controller.
$this->adapter = Ak::db();
$this->all_records = $this->adapter->select('SELECT * FROM table WHERE field=1');
Give you back a nice little assoc array (hash). Very very nice.
Pretty sweet! Thanks Bermi.
1 to 7 of 7