Re: belongsTo not working on a HABTM

2009-01-12 Thread Webweave

Why do you have the echo in test action of your controller ?

That's going to break things even if everything else was OK.

If you set debug to 2 or 3, you should get the SQL that was produced,
which will help diagnose your issue.

I don't think you should be calling the test method in the model, but
rather calling the find('all') for the model you need data from, so
for this scenario (assuming your relationships are correct), you'd
just do:

   function test() {
$this-Blog-recursive = 2;
}

And the data should be there for your test.ctp to display.

On Jan 9, 2:17 am, Miles J mileswjohn...@gmail.com wrote:
 This is still making no sense. Heres my controllers (hid $uses below)
 and models.

 ?php
 // controllers/blog_controller.php
 class BlogController extends AppController {
         function test() {
                 $this-EntriesTopic-test();
                 exit();
         }

 }

 // models/entries_topic.php
 class EntriesTopic extends AppModel {
         var $belongsTo = array('Topic', 'Entry');

         function test() {
                 echo 'test';
                 debug($this-find('all', array('recursive' = 2)));
         }

 } ?

 When I go to /blog/test/ I get the following errors. The damn model is
 not even being initialized, you can see it call AppModel instead of
 EntriesTopic, what am I missing here..

 Warning (512): SQL Error: 1064: You have an error in your SQL syntax;
 check the manual that corresponds to your MySQL server version for the
 right syntax to use near 'test' at line 1 [CORE\cake\libs\model
 \datasources\dbo_source.php, line 514]

 DboSource::showQuery() - CORE\cake\libs\model\datasources
 \dbo_source.php, line 514
 DboSource::execute() - CORE\cake\libs\model\datasources
 \dbo_source.php, line 201
 DboSource::fetchAll() - CORE\cake\libs\model\datasources
 \dbo_source.php, line 337
 DboSource::query() - CORE\cake\libs\model\datasources\dbo_source.php,
 line 298
 Model::call__() - CORE\cake\libs\model\model.php, line 436
 Overloadable::__call() - CORE\cake\libs\overloadable_php5.php, line 52
 AppModel::test() - [internal], line ??
 BlogController::test() - APP\controllers\blog_controller.php, line 52
 Object::dispatchMethod() - CORE\cake\libs\object.php, line 115
 Dispatcher::_invoke() - CORE\cake\dispatcher.php, line 245
 Dispatcher::dispatch() - CORE\cake\dispatcher.php, line 211
 [main] - APP\webroot\index.php, line 88
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: belongsTo not working on a HABTM

2009-01-12 Thread Miles J

Ive tried many different things but simply, I needed to use this model
to paginate with, not the other way around.

I could never get the associations to work, so I had to make a fake
model and do $useTable to the correct table and that worked.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: belongsTo not working on a HABTM

2009-01-12 Thread Webweave

Sounds like there was something wrong with your model in that case.

Did you have your corresponding hasMany/hasOne in your Topic and Entry
models ?

What 'extra data' were you not getting that you expected ?

On Jan 12, 12:50 pm, Miles J mileswjohn...@gmail.com wrote:
 Ive tried many different things but simply, I needed to use this model
 to paginate with, not the other way around.

 I could never get the associations to work, so I had to make a fake
 model and do $useTable to the correct table and that worked.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: belongsTo not working on a HABTM

2009-01-12 Thread Miles J

I needed to paginate based on a condition within the HABTM, so simply
using the parent model would not work.

I had the model name correct because I debug() the controller and it
outputs how the models should be named. Next I thought the file was
named incorrectly, so I renamed it like 9 different ways, and neither
of them worked. I never found the problem though, it was really weird.

I tried the same thing (paginating with HABTM) in another application
and it worked, so Im not sure.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: belongsTo not working on a HABTM

2009-01-09 Thread Miles J

This is still making no sense. Heres my controllers (hid $uses below)
and models.

?php
// controllers/blog_controller.php
class BlogController extends AppController {
function test() {
$this-EntriesTopic-test();
exit();
}
}

// models/entries_topic.php
class EntriesTopic extends AppModel {
var $belongsTo = array('Topic', 'Entry');

function test() {
echo 'test';
debug($this-find('all', array('recursive' = 2)));
}
} ?

When I go to /blog/test/ I get the following errors. The damn model is
not even being initialized, you can see it call AppModel instead of
EntriesTopic, what am I missing here..

Warning (512): SQL Error: 1064: You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the
right syntax to use near 'test' at line 1 [CORE\cake\libs\model
\datasources\dbo_source.php, line 514]

DboSource::showQuery() - CORE\cake\libs\model\datasources
\dbo_source.php, line 514
DboSource::execute() - CORE\cake\libs\model\datasources
\dbo_source.php, line 201
DboSource::fetchAll() - CORE\cake\libs\model\datasources
\dbo_source.php, line 337
DboSource::query() - CORE\cake\libs\model\datasources\dbo_source.php,
line 298
Model::call__() - CORE\cake\libs\model\model.php, line 436
Overloadable::__call() - CORE\cake\libs\overloadable_php5.php, line 52
AppModel::test() - [internal], line ??
BlogController::test() - APP\controllers\blog_controller.php, line 52
Object::dispatchMethod() - CORE\cake\libs\object.php, line 115
Dispatcher::_invoke() - CORE\cake\dispatcher.php, line 245
Dispatcher::dispatch() - CORE\cake\dispatcher.php, line 211
[main] - APP\webroot\index.php, line 88



--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



belongsTo not working on a HABTM

2009-01-08 Thread Miles J

My tables: entries, topics, entries_topics

Now all works fine when grabbing data from Entry or Topic. But when I
try to grab data from EntriesTopic, my belongs to are not even
working. Ive tried so many variations and nothing is working.

?php
// entries_topic.php
class EntriesTopic extends AppModel {
var $belongsTo = array('Topic', 'Entry');
}
?

And my find query:

debug($this-EntriesTopic-find('all', array('conditions' = array
('EntriesTopic.topic_id' = 2), 'recursive' = 2)));

And this is the output. No matter what I change in recursive or
associations, I cant get any extra data.

Array
(
[0] = Array
(
[EntriesTopic] = Array
(
[id] = 6
[entry_id] = 4
[topic_id] = 2
)

)

[1] = Array
(
[EntriesTopic] = Array
(
[id] = 13
[entry_id] = 8
[topic_id] = 2
)

)

)

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---