paginação n:n

3 views
Skip to first unread message

Nicássio Meneguci

unread,
Jun 23, 2009, 9:27:30 PM6/23/09
to Cake PHP Português
Estou com um problema para fazer uma paginacao aplicando um filtro na
tabela telefones, no campo telefone

quando uso o método paginator, ele me retorna um erro dizendo que nao
encontrou o campo, e mostra o select, nele eu reparei que nao faz o o
left join na tabela telefones, somente na tabela agendas_telefones, eu
ja consegui fazer o relacionamento entre elas, pra me mostrar os
dados, mas quando uso o paginator
com a condicação não está dando certo.
alguem poderia me ajudar
segue a estrutura das tabelas:
obrigado
CREATE TABLE IF NOT EXISTS `agendas` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`agenda` varchar(60) NOT NULL,
`prioridade` int(11) NOT NULL DEFAULT '0',
`agendanatureza_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC
AUTO_INCREMENT=3 ;
INSERT INTO `agendas` (`id`, `agenda`, `prioridade`,
`agendanatureza_id`) VALUES
(1, 'Loja de Armas do Beto', 1, 1),
(2, 'Cristal', 3, 2);

CREATE TABLE IF NOT EXISTS `agendas_telefones` (
`agendas_id` int(11) NOT NULL,
`telefones_id` int(11) NOT NULL,
PRIMARY KEY (`agendas_id`,`telefones_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
INSERT INTO `agendas_telefones` (`agendas_id`, `telefones_id`) VALUES
(1, 1),
(1, 2),
(2, 1),
(2, 2);
CREATE TABLE IF NOT EXISTS `telefones` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`telefone` varchar(13) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
INSERT INTO `telefones` (`id`, `telefone`) VALUES
(1, 'aaaaaaaaaaaaa'),
(2, 'aaaaaaaaaaaaa');

Altieres

unread,
Jun 27, 2009, 2:46:12 PM6/27/09
to Cake PHP Português
Nicássio,

Pelo que entendi você está fazendo find na tabela Agenda.
Se você está fazendo buscas por telefones, seus finds deviam ser na
model Telefone. Acredito que devia ser a action index da controller
Telefones.

De qualquer forma, você pode tentar mudar a model que o paginator está
usando, para a Telefone, da seguinte maneira:

$this->paginate('Telefone');

Se precisar exibir dados da agenda, faça um Telefone belongsTo Agenda
e recupere os dados necessários...

att,

---
Altieres Lopes
WebGoal.com.br
Simplificando Softwares

On 23 jun, 22:27, Nicássio Meneguci <nicassio.meneg...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages