HABTM question, really appreciate any help!

2011-02-03 Thread Tan Cheng
I'm a newbie to Cakephp and I am trying to learn the HABTM for the
"post and tag" example.

I have set up the "$hasAndBelongToMany" to both "post" and "tag"
models, also I have created the "posts_tags" join table. I added the
"$scaffold" in the posts and tags controller, when I try to add a new
post, the tags never show up, vice versa. I am really frustrated.

I am attaching the related files in a rar file:
http://www.excelsrmc.com/myFile/relatedFiles.rar

The files are:

post.php
tag.php
posts_controller.php
tags_controller.php

and the .sql database file

I know this is a stupid question, but I really hope someone could
help, really appreciate it.

Thank you very much

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


difficult saveAll HABTM question

2011-02-02 Thread Celso
***Equipamento*** hasBelongToMany ***Recibo***

***EntradaEquipamento*** belongsTo ***Recibo***, ***Equipamento***

In the Equipamento/add view, i have various Equipamento.n.fields, and
for each Equipamento, i need save a EntradaEquipamento too

I tried this array in saveAll, but without success:


Array
(
[EntradaEquipamento] => Array
(
[recibo_id] => 5
)

[Equipamento] => Array
(
[1] => Array
(
[numero_serie] => al001
[codigo_controle] => c12
[tipo_equipamento_id] => 2
[localizacao_id] => 250
[status_equipamento_id] => 1
[user_id] => 1
)

[2] => Array
(
[numero_serie] => al002
[codigo_controle] => c13
[tipo_equipamento_id] => 2
[localizacao_id] => 250
[status_equipamento_id] => 1
[user_id] => 1
)

)

)

How save all this ?

Thanks,
Celso.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM question

2010-12-08 Thread cricket
On Wed, Dec 8, 2010 at 5:42 AM, Jens Dittrich  wrote:
> Hello,
>
> I have the following situation in which i need help:
> There are people, roles and lectures, summer_schools and
> presentations.
> People HABTM roles. Depending on their role people are associated to
> lectures or summer_schools or presentations. So I am planning on
> creating more HABTM-tables called lectures_people_roles,
> people_roles_summer_schools and so on.
>
> Is that supported by cakes ORM(bake)? Is ist configurable manually in
> the models or am I asking to much or just making it more complicated
> than necessary?

I think the latter. You could probably use:

Person HABTM Role
Role <-> Lecture
Rol <-> SummerSchool
Role <-> Presentation

I left the other assoc. blank as you haven't described it enough.
Perhaps hasOne/belongsTo? The upshot of it, though, is that you could
do a find on Person and get:

Person
- Role
- [Lecture|SummerSchool|Presentation]

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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: HABTM question

2010-12-08 Thread huoxito
I believe people_roles_summer_schools wouldn't be a nice table name
for a cakephp app. I once tried to bake something like that and it
didnt work, instead I used a single name for a table which has many
foreign keys.



On 8 dez, 07:42, Jens Dittrich  wrote:
> Hello,
>
> I have the following situation in which i need help:
> There are people, roles and lectures, summer_schools and
> presentations.
> People HABTM roles. Depending on their role people are associated to
> lectures or summer_schools or presentations. So I am planning on
> creating more HABTM-tables called lectures_people_roles,
> people_roles_summer_schools and so on.
>
> Is that supported by cakes ORM(bake)? Is ist configurable manually in
> the models or am I asking to much or just making it more complicated
> than necessary?
>
> thanks in advance,
> jens

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


HABTM question

2010-12-08 Thread Jens Dittrich
Hello,

I have the following situation in which i need help:
There are people, roles and lectures, summer_schools and
presentations.
People HABTM roles. Depending on their role people are associated to
lectures or summer_schools or presentations. So I am planning on
creating more HABTM-tables called lectures_people_roles,
people_roles_summer_schools and so on.

Is that supported by cakes ORM(bake)? Is ist configurable manually in
the models or am I asking to much or just making it more complicated
than necessary?

thanks in advance,
jens

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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: Another HABTM question

2010-10-15 Thread cricket
On Fri, Oct 15, 2010 at 2:39 AM, brybot  wrote:
> I've searched and looked through this group and the online
> documentation for hours, but I'm having some difficulty with a simple
> problem.
>
> Its a simple setup:
>
> User HABTM Permissions
>
> Everything is setup properly (3 tables: users, users_permissions,
> permissions).  And everything works fine, I'm just trying to make a
> simple select.
>
> I want a list of the permission for a certain user.
>
> I can get a list of all permission: $this->Permission->find('list',
> array('fields'=>'id'))
>
> but i cannot seem to find the proper syntax to limit it to one user.
> Everytime I try to limit the results by the user as the HABTM cake
> documentation says:
>
> $this->Permission->User->findById('4',
> array('fields'=>'Permission.*')) or
> $this->Permission->User->find('all',
> array('conditions'=>array('User.id'=>'4'),
> 'fields'=>array('Permission.*')))
>
> The generated query drops the inner join to the permission table, and
> only selects the user.
>
> Or I can get a list of the User and all its Permissions in a rather
> large array, but I cannot get a list.
>

You want just a single User so you should use 'first' not 'all'.

$this->Permission->User->find(
'first',
array(
'conditions'=>array(
'User.id'=> $id
)
)
);

If you're associations are set up correctly, that should pull in the
User's Permissions, also.

Personally, I prefer to use Containable. Because I use it a lot, I
declare it in AppModel::actsAs array.


$this->Permission->User->find(
'first',
array(
'conditions'=>array(
'User.id'=> $id
),
'contain' => array(
'Permission' => array(
'fields' => array(
'Permission.id',
'Permission.name'
)
)
)
)
);

Or, you could declare the HABTM assoc with a 'with' model[1] and run
the find on that. But I suppose that would give you just the
Permission.id and not the name (or whatever column you're using. But
maybe that's all you want. Or, if you use the above code, you could
then use Set::extract() to create your list.

[1] 
http://marianoiglesias.com.ar/cakephp/modelizing-habtm-join-tables-in-cakephp-1-2-with-and-auto-with-models/

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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: Another HABTM question

2010-10-15 Thread Jeremy Burns | Class Outfit
The join table has to be in alphabetical order, so try permissions_users.

Jeremy Burns
Class Outfit

jeremybu...@classoutfit.com
http://www.classoutfit.com

On 15 Oct 2010, at 07:39, brybot wrote:

> I've searched and looked through this group and the online
> documentation for hours, but I'm having some difficulty with a simple
> problem.
> 
> Its a simple setup:
> 
> User HABTM Permissions
> 
> Everything is setup properly (3 tables: users, users_permissions,
> permissions).  And everything works fine, I'm just trying to make a
> simple select.
> 
> I want a list of the permission for a certain user.
> 
> I can get a list of all permission: $this->Permission->find('list',
> array('fields'=>'id'))
> 
> but i cannot seem to find the proper syntax to limit it to one user.
> Everytime I try to limit the results by the user as the HABTM cake
> documentation says:
> 
> $this->Permission->User->findById('4',
> array('fields'=>'Permission.*')) or
> $this->Permission->User->find('all',
> array('conditions'=>array('User.id'=>'4'),
> 'fields'=>array('Permission.*')))
> 
> The generated query drops the inner join to the permission table, and
> only selects the user.
> 
> Or I can get a list of the User and all its Permissions in a rather
> large array, but I cannot get a list.
> 
> Can anyone help?
> 
> Check out the new CakePHP Questions site http://cakeqs.org and help others 
> with their CakePHP related questions.
> 
> 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

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Another HABTM question

2010-10-15 Thread brybot
I've searched and looked through this group and the online
documentation for hours, but I'm having some difficulty with a simple
problem.

Its a simple setup:

User HABTM Permissions

Everything is setup properly (3 tables: users, users_permissions,
permissions).  And everything works fine, I'm just trying to make a
simple select.

I want a list of the permission for a certain user.

I can get a list of all permission: $this->Permission->find('list',
array('fields'=>'id'))

but i cannot seem to find the proper syntax to limit it to one user.
Everytime I try to limit the results by the user as the HABTM cake
documentation says:

$this->Permission->User->findById('4',
array('fields'=>'Permission.*')) or
$this->Permission->User->find('all',
array('conditions'=>array('User.id'=>'4'),
'fields'=>array('Permission.*')))

The generated query drops the inner join to the permission table, and
only selects the user.

Or I can get a list of the User and all its Permissions in a rather
large array, but I cannot get a list.

Can anyone help?

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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: HABTM Question.

2010-05-28 Thread Roland Pish
Thanks Jeremy!
In the link you supplied, after reading the portion "...(group ->
groups in this case, or ExtraFunkyModel -> extraFunkyModels).." now it
all makes sense.

Regards.

On 28 mayo, 23:13, Jeremy Burns  wrote:
> It isn't just restricted to HABTM, it's a standard thing. But here's a page 
> that refers specifically to HABTM:
>
> http://book.cakephp.org/view/1390/Automagic-Form-Elements
>
> Jeremy Burns
> jeremybu...@me.com
>
> On 29 May 2010, at 06:10, Roland Pish wrote:
>
> > It worked!!
> > Finally!!
>
> > There was something weird in the database. I submitted the form and
> > magically the select was populated and funny tags were selected.
>
> > I really appreciate your help Jeremy.
>
> > One last question, where is in cake manual the convention you advised
> > to fix this (the use of $funnyTags)?
>
> > Best regards.
>
> > On 28 mayo, 22:57, Roland Pish  wrote:
> >> Thanks, We are getting closer!!
>
> >> After using $funnyTags now the select is populated correctly but the
> >> funny tags aren't selected according to what is on the database.
>
> >> I tried this: echo $form->input('FunnyTag'); but the funny tags aren't
> >> still selected.
>
> >> On 28 mayo, 22:51, Jeremy Burns  wrote:
>
> >>> Ah. Try this:
>
> >>> $funnyTags = 
> >>> $this->Post->FunnyTag->find('list',array('fields'=>array('id','name')));
>
> >>> If that doesn't fix it, try this as well:
>
> >>> echo $form->input('FunnyTag');
>
> >>> Jeremy Burns
> >>> jeremybu...@me.com
>
> >>> On 29 May 2010, at 05:46, Roland Pish wrote:
>
>  I think I'll post the code and information here. I still don't know
>  what is happening.
>
>  Any help is hugely appreciated.
>
>  The tables:
>  funny_tags: id,name
>  funny_tags_posts: id,funny_tag_id,post_id
>  posts: id,name,body
>
>  The files:
>  + Under models: post.php and funny_tag.php
>  + Under controllers: posts_controller.php
>  + Under views/posts: form.ctp
>
>  Contents of funny_tag.php:
>  class FunnyTag extends AppModel {
>     var $name = 'FunnyTag';
>  }
>
>  Contents of post.php:
>  class Post extends AppModel {
>     var $name = 'Post';
>
>     var $hasAndBelongsToMany = array(
>             'FunnyTag' => array(
>                     'className' => 'FunnyTag',
>                     'joinTable' => 'funny_tags_posts',
>                     'foreignKey' => 'post_id',
>                     'associationForeignKey' => 'funny_tag_id',
>                     /*'with' => 'PostToTag',*/
>             ),
>     );
>
>  }
>
>  Contents of posts_controller.php:
>  class PostsController extends AppController {
>     var $name = 'Posts';
>
>     function form($id = null) {
>             if (!empty($this->data)) {
>                     // form sends data as:
>                     // $this->data['Post']['Tag']['Tag'][1] = 1;
>                     // $this->data['Post']['Tag']['Tag'][3] = 3;
>
>                     // save the data (auto-handles habtm save)
>                     $this->Post->create();
>                     if ($this->Post->save($this->data)) {
>                             $this->Session->setFlash(__('The Post has 
>  been saved.',true));
>                             
>  $this->redirect(array('action'=>'form',$this->Post->id));
>                     }
>                     else {
>                             $this->Session->setFlash(__('The Post could 
>  not be saved. Please,
>  try again.'),true);
>                     }
>             }
>             if (empty($this->data)) {
>                     $this->data = $this->Post->read(null, $id);
>             }
>             $funny_tags = $this->Post->FunnyTag-
> > find('list',array('fields'=>array('id','name')));
>             $this->set(compact('funny_tags'));
>     }
>  }
>
>  Contents of form.ctp:
>   > create('Post',array('url'=>array('action'=>'form')));?>
>     
>             
>                          echo $form->input('id');
>             echo $form->input('name');
>             echo $form->input('body');
>             echo $form->input('FunnyTag.FunnyTag');
>             ?>
>     
>  end('Submit');?>
>
>  On 28 mayo, 22:08, Roland Pish  wrote:
> > Thanks Jeremy.
> > In fact I did that and didn't solve the problem.
>
> > I'm still trying but with no success yet.
>
> > Regards.
>
> > On 28 mayo, 21:24, Jeremy Burns  wrote:
>
> >> I am *guessing* that your variable that contains your funny_tags is 
> >> not being set correctly. It is set here:
>
> >> $tags = 
> >> $this->Post->Tag->find('list',array('fields'=>array('id','name')));
>
> >> ...so change that to:
>
> >> $funny_tags = 
> >> $this->Post->FunnyTag->find('list',array('fields'=>array('id','name')));
>
> >> ...and change this:
> >> $th

Re: HABTM Question.

2010-05-28 Thread Jeremy Burns
It isn't just restricted to HABTM, it's a standard thing. But here's a page 
that refers specifically to HABTM:

http://book.cakephp.org/view/1390/Automagic-Form-Elements

Jeremy Burns
jeremybu...@me.com


On 29 May 2010, at 06:10, Roland Pish wrote:

> It worked!!
> Finally!!
> 
> There was something weird in the database. I submitted the form and
> magically the select was populated and funny tags were selected.
> 
> I really appreciate your help Jeremy.
> 
> One last question, where is in cake manual the convention you advised
> to fix this (the use of $funnyTags)?
> 
> Best regards.
> 
> 
> On 28 mayo, 22:57, Roland Pish  wrote:
>> Thanks, We are getting closer!!
>> 
>> After using $funnyTags now the select is populated correctly but the
>> funny tags aren't selected according to what is on the database.
>> 
>> I tried this: echo $form->input('FunnyTag'); but the funny tags aren't
>> still selected.
>> 
>> On 28 mayo, 22:51, Jeremy Burns  wrote:
>> 
>>> Ah. Try this:
>> 
>>> $funnyTags = 
>>> $this->Post->FunnyTag->find('list',array('fields'=>array('id','name')));
>> 
>>> If that doesn't fix it, try this as well:
>> 
>>> echo $form->input('FunnyTag');
>> 
>>> Jeremy Burns
>>> jeremybu...@me.com
>> 
>>> On 29 May 2010, at 05:46, Roland Pish wrote:
>> 
 I think I'll post the code and information here. I still don't know
 what is happening.
>> 
 Any help is hugely appreciated.
>> 
 The tables:
 funny_tags: id,name
 funny_tags_posts: id,funny_tag_id,post_id
 posts: id,name,body
>> 
 The files:
 + Under models: post.php and funny_tag.php
 + Under controllers: posts_controller.php
 + Under views/posts: form.ctp
>> 
 Contents of funny_tag.php:
 class FunnyTag extends AppModel {
var $name = 'FunnyTag';
 }
>> 
 Contents of post.php:
 class Post extends AppModel {
var $name = 'Post';
>> 
var $hasAndBelongsToMany = array(
'FunnyTag' => array(
'className' => 'FunnyTag',
'joinTable' => 'funny_tags_posts',
'foreignKey' => 'post_id',
'associationForeignKey' => 'funny_tag_id',
/*'with' => 'PostToTag',*/
),
);
>> 
 }
>> 
 Contents of posts_controller.php:
 class PostsController extends AppController {
var $name = 'Posts';
>> 
function form($id = null) {
if (!empty($this->data)) {
// form sends data as:
// $this->data['Post']['Tag']['Tag'][1] = 1;
// $this->data['Post']['Tag']['Tag'][3] = 3;
>> 
// save the data (auto-handles habtm save)
$this->Post->create();
if ($this->Post->save($this->data)) {
$this->Session->setFlash(__('The Post has been 
 saved.',true));

 $this->redirect(array('action'=>'form',$this->Post->id));
}
else {
$this->Session->setFlash(__('The Post could not 
 be saved. Please,
 try again.'),true);
}
}
if (empty($this->data)) {
$this->data = $this->Post->read(null, $id);
}
$funny_tags = $this->Post->FunnyTag-
> find('list',array('fields'=>array('id','name')));
$this->set(compact('funny_tags'));
}
 }
>> 
 Contents of form.ctp:
  create('Post',array('url'=>array('action'=>'form')));?>


>>>echo $form->input('id');
echo $form->input('name');
echo $form->input('body');
echo $form->input('FunnyTag.FunnyTag');
?>

 end('Submit');?>
>> 
 On 28 mayo, 22:08, Roland Pish  wrote:
> Thanks Jeremy.
> In fact I did that and didn't solve the problem.
>> 
> I'm still trying but with no success yet.
>> 
> Regards.
>> 
> On 28 mayo, 21:24, Jeremy Burns  wrote:
>> 
>> I am *guessing* that your variable that contains your funny_tags is not 
>> being set correctly. It is set here:
>> 
>> $tags = 
>> $this->Post->Tag->find('list',array('fields'=>array('id','name')));
>> 
>> ...so change that to:
>> 
>> $funny_tags = 
>> $this->Post->FunnyTag->find('list',array('fields'=>array('id','name')));
>> 
>> ...and change this:
>> $this->set(compact('tags'));
>> 
>> ...to this:
>> $this->set(compact('funny_tags'));
>> 
>> Does that resolve it?
>> 
>> Jeremy Burns
>> jeremybu...@me.com
>> 
>> On 29 May 2010, at 04:20, Roland Pish wrote:
>> 
>>> Hi!
>>> I've been struggling for a long time with something and I don't seem
>>> to get it.
>>> I did the Posts/Tags HABTM Select e

Re: HABTM Question.

2010-05-28 Thread Roland Pish
It worked!!
Finally!!

There was something weird in the database. I submitted the form and
magically the select was populated and funny tags were selected.

I really appreciate your help Jeremy.

One last question, where is in cake manual the convention you advised
to fix this (the use of $funnyTags)?

Best regards.


On 28 mayo, 22:57, Roland Pish  wrote:
> Thanks, We are getting closer!!
>
> After using $funnyTags now the select is populated correctly but the
> funny tags aren't selected according to what is on the database.
>
> I tried this: echo $form->input('FunnyTag'); but the funny tags aren't
> still selected.
>
> On 28 mayo, 22:51, Jeremy Burns  wrote:
>
> > Ah. Try this:
>
> > $funnyTags = 
> > $this->Post->FunnyTag->find('list',array('fields'=>array('id','name')));
>
> > If that doesn't fix it, try this as well:
>
> > echo $form->input('FunnyTag');
>
> > Jeremy Burns
> > jeremybu...@me.com
>
> > On 29 May 2010, at 05:46, Roland Pish wrote:
>
> > > I think I'll post the code and information here. I still don't know
> > > what is happening.
>
> > > Any help is hugely appreciated.
>
> > > The tables:
> > > funny_tags: id,name
> > > funny_tags_posts: id,funny_tag_id,post_id
> > > posts: id,name,body
>
> > > The files:
> > > + Under models: post.php and funny_tag.php
> > > + Under controllers: posts_controller.php
> > > + Under views/posts: form.ctp
>
> > > Contents of funny_tag.php:
> > > class FunnyTag extends AppModel {
> > >    var $name = 'FunnyTag';
> > > }
>
> > > Contents of post.php:
> > > class Post extends AppModel {
> > >    var $name = 'Post';
>
> > >    var $hasAndBelongsToMany = array(
> > >            'FunnyTag' => array(
> > >                    'className' => 'FunnyTag',
> > >                    'joinTable' => 'funny_tags_posts',
> > >                    'foreignKey' => 'post_id',
> > >                    'associationForeignKey' => 'funny_tag_id',
> > >                    /*'with' => 'PostToTag',*/
> > >            ),
> > >    );
>
> > > }
>
> > > Contents of posts_controller.php:
> > > class PostsController extends AppController {
> > >    var $name = 'Posts';
>
> > >    function form($id = null) {
> > >            if (!empty($this->data)) {
> > >                    // form sends data as:
> > >                    // $this->data['Post']['Tag']['Tag'][1] = 1;
> > >                    // $this->data['Post']['Tag']['Tag'][3] = 3;
>
> > >                    // save the data (auto-handles habtm save)
> > >                    $this->Post->create();
> > >                    if ($this->Post->save($this->data)) {
> > >                            $this->Session->setFlash(__('The Post has been 
> > > saved.',true));
> > >                            
> > > $this->redirect(array('action'=>'form',$this->Post->id));
> > >                    }
> > >                    else {
> > >                            $this->Session->setFlash(__('The Post could 
> > > not be saved. Please,
> > > try again.'),true);
> > >                    }
> > >            }
> > >            if (empty($this->data)) {
> > >                    $this->data = $this->Post->read(null, $id);
> > >            }
> > >            $funny_tags = $this->Post->FunnyTag-
> > >> find('list',array('fields'=>array('id','name')));
> > >            $this->set(compact('funny_tags'));
> > >    }
> > > }
>
> > > Contents of form.ctp:
> > >  > >> create('Post',array('url'=>array('action'=>'form')));?>
> > >    
> > >            
> > >             > >            echo $form->input('id');
> > >            echo $form->input('name');
> > >            echo $form->input('body');
> > >            echo $form->input('FunnyTag.FunnyTag');
> > >            ?>
> > >    
> > > end('Submit');?>
>
> > > On 28 mayo, 22:08, Roland Pish  wrote:
> > >> Thanks Jeremy.
> > >> In fact I did that and didn't solve the problem.
>
> > >> I'm still trying but with no success yet.
>
> > >> Regards.
>
> > >> On 28 mayo, 21:24, Jeremy Burns  wrote:
>
> > >>> I am *guessing* that your variable that contains your funny_tags is not 
> > >>> being set correctly. It is set here:
>
> > >>> $tags = 
> > >>> $this->Post->Tag->find('list',array('fields'=>array('id','name')));
>
> > >>> ...so change that to:
>
> > >>> $funny_tags = 
> > >>> $this->Post->FunnyTag->find('list',array('fields'=>array('id','name')));
>
> > >>> ...and change this:
> > >>> $this->set(compact('tags'));
>
> > >>> ...to this:
> > >>> $this->set(compact('funny_tags'));
>
> > >>> Does that resolve it?
>
> > >>> Jeremy Burns
> > >>> jeremybu...@me.com
>
> > >>> On 29 May 2010, at 04:20, Roland Pish wrote:
>
> >  Hi!
> >  I've been struggling for a long time with something and I don't seem
> >  to get it.
> >  I did the Posts/Tags HABTM Select example from this page:
>
> > http://mrphp.com.au/code/working-habtm-form-data-cakephp
>
> >  So far so good, everything works ok.
>
> >  I wanted to try the same example but asumming that the table tags is
> >  now called funny_tags (just to make

Re: HABTM Question.

2010-05-28 Thread Roland Pish
Thanks, We are getting closer!!

After using $funnyTags now the select is populated correctly but the
funny tags aren't selected according to what is on the database.

I tried this: echo $form->input('FunnyTag'); but the funny tags aren't
still selected.

On 28 mayo, 22:51, Jeremy Burns  wrote:
> Ah. Try this:
>
> $funnyTags = 
> $this->Post->FunnyTag->find('list',array('fields'=>array('id','name')));
>
> If that doesn't fix it, try this as well:
>
> echo $form->input('FunnyTag');
>
> Jeremy Burns
> jeremybu...@me.com
>
> On 29 May 2010, at 05:46, Roland Pish wrote:
>
> > I think I'll post the code and information here. I still don't know
> > what is happening.
>
> > Any help is hugely appreciated.
>
> > The tables:
> > funny_tags: id,name
> > funny_tags_posts: id,funny_tag_id,post_id
> > posts: id,name,body
>
> > The files:
> > + Under models: post.php and funny_tag.php
> > + Under controllers: posts_controller.php
> > + Under views/posts: form.ctp
>
> > Contents of funny_tag.php:
> > class FunnyTag extends AppModel {
> >    var $name = 'FunnyTag';
> > }
>
> > Contents of post.php:
> > class Post extends AppModel {
> >    var $name = 'Post';
>
> >    var $hasAndBelongsToMany = array(
> >            'FunnyTag' => array(
> >                    'className' => 'FunnyTag',
> >                    'joinTable' => 'funny_tags_posts',
> >                    'foreignKey' => 'post_id',
> >                    'associationForeignKey' => 'funny_tag_id',
> >                    /*'with' => 'PostToTag',*/
> >            ),
> >    );
>
> > }
>
> > Contents of posts_controller.php:
> > class PostsController extends AppController {
> >    var $name = 'Posts';
>
> >    function form($id = null) {
> >            if (!empty($this->data)) {
> >                    // form sends data as:
> >                    // $this->data['Post']['Tag']['Tag'][1] = 1;
> >                    // $this->data['Post']['Tag']['Tag'][3] = 3;
>
> >                    // save the data (auto-handles habtm save)
> >                    $this->Post->create();
> >                    if ($this->Post->save($this->data)) {
> >                            $this->Session->setFlash(__('The Post has been 
> > saved.',true));
> >                            
> > $this->redirect(array('action'=>'form',$this->Post->id));
> >                    }
> >                    else {
> >                            $this->Session->setFlash(__('The Post could not 
> > be saved. Please,
> > try again.'),true);
> >                    }
> >            }
> >            if (empty($this->data)) {
> >                    $this->data = $this->Post->read(null, $id);
> >            }
> >            $funny_tags = $this->Post->FunnyTag-
> >> find('list',array('fields'=>array('id','name')));
> >            $this->set(compact('funny_tags'));
> >    }
> > }
>
> > Contents of form.ctp:
> >  >> create('Post',array('url'=>array('action'=>'form')));?>
> >    
> >            
> >             >            echo $form->input('id');
> >            echo $form->input('name');
> >            echo $form->input('body');
> >            echo $form->input('FunnyTag.FunnyTag');
> >            ?>
> >    
> > end('Submit');?>
>
> > On 28 mayo, 22:08, Roland Pish  wrote:
> >> Thanks Jeremy.
> >> In fact I did that and didn't solve the problem.
>
> >> I'm still trying but with no success yet.
>
> >> Regards.
>
> >> On 28 mayo, 21:24, Jeremy Burns  wrote:
>
> >>> I am *guessing* that your variable that contains your funny_tags is not 
> >>> being set correctly. It is set here:
>
> >>> $tags = 
> >>> $this->Post->Tag->find('list',array('fields'=>array('id','name')));
>
> >>> ...so change that to:
>
> >>> $funny_tags = 
> >>> $this->Post->FunnyTag->find('list',array('fields'=>array('id','name')));
>
> >>> ...and change this:
> >>> $this->set(compact('tags'));
>
> >>> ...to this:
> >>> $this->set(compact('funny_tags'));
>
> >>> Does that resolve it?
>
> >>> Jeremy Burns
> >>> jeremybu...@me.com
>
> >>> On 29 May 2010, at 04:20, Roland Pish wrote:
>
>  Hi!
>  I've been struggling for a long time with something and I don't seem
>  to get it.
>  I did the Posts/Tags HABTM Select example from this page:
>
> http://mrphp.com.au/code/working-habtm-form-data-cakephp
>
>  So far so good, everything works ok.
>
>  I wanted to try the same example but asumming that the table tags is
>  now called funny_tags (just to make a test with a more complex table
>  names), so the model now is FunnyTag and the join table is
>  funny_tags_posts and I did the all the changes needed according to
>  cake naming conventions.
>  The problem is that this example no longer populates the select list.
>
>  Has anyone looked at this example before?
>  How can this must be modified to work with table complex names as
>  funny_tags_posts?
>
>  I really appreciate you help.
>
>  Regards.
>
>  Check out the new CakePHP Questions sitehttp://cakeqs.organdhelpothers 
>  with their Cake

Re: HABTM Question.

2010-05-28 Thread Jeremy Burns
Ah. Try this:

$funnyTags = 
$this->Post->FunnyTag->find('list',array('fields'=>array('id','name')));

If that doesn't fix it, try this as well:

echo $form->input('FunnyTag');


Jeremy Burns
jeremybu...@me.com


On 29 May 2010, at 05:46, Roland Pish wrote:

> I think I'll post the code and information here. I still don't know
> what is happening.
> 
> Any help is hugely appreciated.
> 
> The tables:
> funny_tags: id,name
> funny_tags_posts: id,funny_tag_id,post_id
> posts: id,name,body
> 
> The files:
> + Under models: post.php and funny_tag.php
> + Under controllers: posts_controller.php
> + Under views/posts: form.ctp
> 
> Contents of funny_tag.php:
> class FunnyTag extends AppModel {
>   var $name = 'FunnyTag';
> }
> 
> Contents of post.php:
> class Post extends AppModel {
>   var $name = 'Post';
> 
>   var $hasAndBelongsToMany = array(
>   'FunnyTag' => array(
>   'className' => 'FunnyTag',
>   'joinTable' => 'funny_tags_posts',
>   'foreignKey' => 'post_id',
>   'associationForeignKey' => 'funny_tag_id',
>   /*'with' => 'PostToTag',*/
>   ),
>   );
> 
> }
> 
> Contents of posts_controller.php:
> class PostsController extends AppController {
>   var $name = 'Posts';
> 
>   function form($id = null) {
>   if (!empty($this->data)) {
>   // form sends data as:
>   // $this->data['Post']['Tag']['Tag'][1] = 1;
>   // $this->data['Post']['Tag']['Tag'][3] = 3;
> 
>   // save the data (auto-handles habtm save)
>   $this->Post->create();
>   if ($this->Post->save($this->data)) {
>   $this->Session->setFlash(__('The Post has been 
> saved.',true));
>   
> $this->redirect(array('action'=>'form',$this->Post->id));
>   }
>   else {
>   $this->Session->setFlash(__('The Post could not 
> be saved. Please,
> try again.'),true);
>   }
>   }
>   if (empty($this->data)) {
>   $this->data = $this->Post->read(null, $id);
>   }
>   $funny_tags = $this->Post->FunnyTag-
>> find('list',array('fields'=>array('id','name')));
>   $this->set(compact('funny_tags'));
>   }
> }
> 
> Contents of form.ctp:
> > create('Post',array('url'=>array('action'=>'form')));?>
>   
>   
>  echo $form->input('id');
>   echo $form->input('name');
>   echo $form->input('body');
>   echo $form->input('FunnyTag.FunnyTag');
>   ?>
>   
> end('Submit');?>
> 
> On 28 mayo, 22:08, Roland Pish  wrote:
>> Thanks Jeremy.
>> In fact I did that and didn't solve the problem.
>> 
>> I'm still trying but with no success yet.
>> 
>> Regards.
>> 
>> On 28 mayo, 21:24, Jeremy Burns  wrote:
>> 
>>> I am *guessing* that your variable that contains your funny_tags is not 
>>> being set correctly. It is set here:
>> 
>>> $tags = $this->Post->Tag->find('list',array('fields'=>array('id','name')));
>> 
>>> ...so change that to:
>> 
>>> $funny_tags = 
>>> $this->Post->FunnyTag->find('list',array('fields'=>array('id','name')));
>> 
>>> ...and change this:
>>> $this->set(compact('tags'));
>> 
>>> ...to this:
>>> $this->set(compact('funny_tags'));
>> 
>>> Does that resolve it?
>> 
>>> Jeremy Burns
>>> jeremybu...@me.com
>> 
>>> On 29 May 2010, at 04:20, Roland Pish wrote:
>> 
 Hi!
 I've been struggling for a long time with something and I don't seem
 to get it.
 I did the Posts/Tags HABTM Select example from this page:
>> 
 http://mrphp.com.au/code/working-habtm-form-data-cakephp
>> 
 So far so good, everything works ok.
>> 
 I wanted to try the same example but asumming that the table tags is
 now called funny_tags (just to make a test with a more complex table
 names), so the model now is FunnyTag and the join table is
 funny_tags_posts and I did the all the changes needed according to
 cake naming conventions.
 The problem is that this example no longer populates the select list.
>> 
 Has anyone looked at this example before?
 How can this must be modified to work with table complex names as
 funny_tags_posts?
>> 
 I really appreciate you help.
>> 
 Regards.
>> 
 Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp others 
 with their CakePHP related questions.
>> 
 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 
 athttp://groups.google.com/grou

Re: HABTM Question.

2010-05-28 Thread Roland Pish
I think I'll post the code and information here. I still don't know
what is happening.

Any help is hugely appreciated.

The tables:
funny_tags: id,name
funny_tags_posts: id,funny_tag_id,post_id
posts: id,name,body

The files:
+ Under models: post.php and funny_tag.php
+ Under controllers: posts_controller.php
+ Under views/posts: form.ctp

Contents of funny_tag.php:
class FunnyTag extends AppModel {
var $name = 'FunnyTag';
}

Contents of post.php:
class Post extends AppModel {
var $name = 'Post';

var $hasAndBelongsToMany = array(
'FunnyTag' => array(
'className' => 'FunnyTag',
'joinTable' => 'funny_tags_posts',
'foreignKey' => 'post_id',
'associationForeignKey' => 'funny_tag_id',
/*'with' => 'PostToTag',*/
),
);

}

Contents of posts_controller.php:
class PostsController extends AppController {
var $name = 'Posts';

function form($id = null) {
if (!empty($this->data)) {
// form sends data as:
// $this->data['Post']['Tag']['Tag'][1] = 1;
// $this->data['Post']['Tag']['Tag'][3] = 3;

// save the data (auto-handles habtm save)
$this->Post->create();
if ($this->Post->save($this->data)) {
$this->Session->setFlash(__('The Post has been 
saved.',true));

$this->redirect(array('action'=>'form',$this->Post->id));
}
else {
$this->Session->setFlash(__('The Post could not 
be saved. Please,
try again.'),true);
}
}
if (empty($this->data)) {
$this->data = $this->Post->read(null, $id);
}
$funny_tags = $this->Post->FunnyTag-
>find('list',array('fields'=>array('id','name')));
$this->set(compact('funny_tags'));
}
}

Contents of form.ctp:
create('Post',array('url'=>array('action'=>'form')));?>


input('id');
echo $form->input('name');
echo $form->input('body');
echo $form->input('FunnyTag.FunnyTag');
?>

end('Submit');?>

On 28 mayo, 22:08, Roland Pish  wrote:
> Thanks Jeremy.
> In fact I did that and didn't solve the problem.
>
> I'm still trying but with no success yet.
>
> Regards.
>
> On 28 mayo, 21:24, Jeremy Burns  wrote:
>
> > I am *guessing* that your variable that contains your funny_tags is not 
> > being set correctly. It is set here:
>
> > $tags = $this->Post->Tag->find('list',array('fields'=>array('id','name')));
>
> > ...so change that to:
>
> > $funny_tags = 
> > $this->Post->FunnyTag->find('list',array('fields'=>array('id','name')));
>
> > ...and change this:
> > $this->set(compact('tags'));
>
> > ...to this:
> > $this->set(compact('funny_tags'));
>
> > Does that resolve it?
>
> > Jeremy Burns
> > jeremybu...@me.com
>
> > On 29 May 2010, at 04:20, Roland Pish wrote:
>
> > > Hi!
> > > I've been struggling for a long time with something and I don't seem
> > > to get it.
> > > I did the Posts/Tags HABTM Select example from this page:
>
> > >http://mrphp.com.au/code/working-habtm-form-data-cakephp
>
> > > So far so good, everything works ok.
>
> > > I wanted to try the same example but asumming that the table tags is
> > > now called funny_tags (just to make a test with a more complex table
> > > names), so the model now is FunnyTag and the join table is
> > > funny_tags_posts and I did the all the changes needed according to
> > > cake naming conventions.
> > > The problem is that this example no longer populates the select list.
>
> > > Has anyone looked at this example before?
> > > How can this must be modified to work with table complex names as
> > > funny_tags_posts?
>
> > > I really appreciate you help.
>
> > > Regards.
>
> > > Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp others 
> > > with their CakePHP related questions.
>
> > > 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 
> > > athttp://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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, vis

Re: HABTM Question.

2010-05-28 Thread Roland Pish
Thanks Jeremy.
In fact I did that and didn't solve the problem.

I'm still trying but with no success yet.

Regards.

On 28 mayo, 21:24, Jeremy Burns  wrote:
> I am *guessing* that your variable that contains your funny_tags is not being 
> set correctly. It is set here:
>
> $tags = $this->Post->Tag->find('list',array('fields'=>array('id','name')));
>
> ...so change that to:
>
> $funny_tags = 
> $this->Post->FunnyTag->find('list',array('fields'=>array('id','name')));
>
> ...and change this:
> $this->set(compact('tags'));
>
> ...to this:
> $this->set(compact('funny_tags'));
>
> Does that resolve it?
>
> Jeremy Burns
> jeremybu...@me.com
>
> On 29 May 2010, at 04:20, Roland Pish wrote:
>
> > Hi!
> > I've been struggling for a long time with something and I don't seem
> > to get it.
> > I did the Posts/Tags HABTM Select example from this page:
>
> >http://mrphp.com.au/code/working-habtm-form-data-cakephp
>
> > So far so good, everything works ok.
>
> > I wanted to try the same example but asumming that the table tags is
> > now called funny_tags (just to make a test with a more complex table
> > names), so the model now is FunnyTag and the join table is
> > funny_tags_posts and I did the all the changes needed according to
> > cake naming conventions.
> > The problem is that this example no longer populates the select list.
>
> > Has anyone looked at this example before?
> > How can this must be modified to work with table complex names as
> > funny_tags_posts?
>
> > I really appreciate you help.
>
> > Regards.
>
> > Check out the new CakePHP Questions sitehttp://cakeqs.organd help others 
> > with their CakePHP related questions.
>
> > 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 
> > athttp://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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: HABTM Question.

2010-05-28 Thread Jeremy Burns
I am *guessing* that your variable that contains your funny_tags is not being 
set correctly. It is set here:

$tags = $this->Post->Tag->find('list',array('fields'=>array('id','name')));

...so change that to:

$funny_tags = 
$this->Post->FunnyTag->find('list',array('fields'=>array('id','name')));

...and change this:
$this->set(compact('tags'));

...to this:
$this->set(compact('funny_tags'));

Does that resolve it?

Jeremy Burns
jeremybu...@me.com


On 29 May 2010, at 04:20, Roland Pish wrote:

> Hi!
> I've been struggling for a long time with something and I don't seem
> to get it.
> I did the Posts/Tags HABTM Select example from this page:
> 
> http://mrphp.com.au/code/working-habtm-form-data-cakephp
> 
> So far so good, everything works ok.
> 
> I wanted to try the same example but asumming that the table tags is
> now called funny_tags (just to make a test with a more complex table
> names), so the model now is FunnyTag and the join table is
> funny_tags_posts and I did the all the changes needed according to
> cake naming conventions.
> The problem is that this example no longer populates the select list.
> 
> Has anyone looked at this example before?
> How can this must be modified to work with table complex names as
> funny_tags_posts?
> 
> I really appreciate you help.
> 
> Regards.
> 
> Check out the new CakePHP Questions site http://cakeqs.org and help others 
> with their CakePHP related questions.
> 
> 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

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


HABTM Question.

2010-05-28 Thread Roland Pish
Hi!
I've been struggling for a long time with something and I don't seem
to get it.
I did the Posts/Tags HABTM Select example from this page:

http://mrphp.com.au/code/working-habtm-form-data-cakephp

So far so good, everything works ok.

I wanted to try the same example but asumming that the table tags is
now called funny_tags (just to make a test with a more complex table
names), so the model now is FunnyTag and the join table is
funny_tags_posts and I did the all the changes needed according to
cake naming conventions.
The problem is that this example no longer populates the select list.

Has anyone looked at this example before?
How can this must be modified to work with table complex names as
funny_tags_posts?

I really appreciate you help.

Regards.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Another HABTM question with checkboxes

2010-01-22 Thread Binu
Hi,

I have a table structure like this

admins  tablehabtm rights table   belongs to rights_groups

In view I need to print like this as checkbox
Rights_group Name1
Rights1
Rights2
Rights_group Name2
Rights3
Rights4

View code (Since I have to give the group name, I need to loop through
the records)
$checked = $form->value('Right.Right');
foreach ($rights as $id => $item) {
// Here Im printing the group name with some condition
echo $form->input("Right.checked." . $item['Right']['id'],
array(
'label'=> $item['Right']['name'],
'type'=>'checkbox',
'checked'=>(isset($checked[$item
['Right']['id']])?'checked':false),
));
}

All these are working fine, but it is not saving the records in the
join table. If I give in the following way, it is working (but I need
to show the group name in between)...
echo $form->input('right', array('div' => false, 'label' => false,
'class' => 'otherforms', 'type' => 'select', 'multiple' =>
'checkbox'));

Any help ?

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


HABTM Question

2010-01-03 Thread Dave
I am back to working with additional fields in a HABTM and going to try the
method as described in the cookbook.
 
"Child hasMany Membership
Membership belongsTo Child, Club
Club hasMany Membership."
 
In my setup I have User, Skill, Year, Skillset and UsersSkill but not sure
of setting up the relationship properly. (no HABTM relations in the site
anymore)
 
Year = the years to select from (0 -6 months, 1-5 yearsso on)
Skill = the available options of skills to select from (Math,
Gym,History)
Skillset = simply groups the Skill into a category (Educational, Extra
Cirricular.)(Skillset also allows me to pull skills specific to Skill
thats why I added that in so rather than having a table for educational,
extra_curricualr and all the other sets I just grouped them in 1 table)
UsersSkill = user_id, skill_id, skillst_id, year_id (this holds all of the
Users skills)
 
So basicaly i render a form that has all the Skill options name with a
dropdown of Years to select beside each Skill so if a User selects 0 -6
months beside Gym they are saying thy have taught Gym for 0-6 months. 
 
Gym [year dropdown]
Math [year dropdown]
History [year dropdown]
 
 
So in UsersSkills the user_id, skill_id, year_id and the skillset_id get
saved
 
But not sure if i have the relations correct. When i go to edit / add a user
i am getting Skills by User->UsersSkill->Skill.
 
Should it be like?
 
User hasMany Skill
Skill belongsTo User, Skillset
Skillset belongsTo User
Skillset hasMany User
Skillset hasMany Year
Skillset hasMany Skill
 
But where does UsersSkill fit in? Completely confused.
 
can someone explain the correct way or where i have gone wrong.
 
Thanks
 
 
Dave

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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: HABTM question - keeping associated records in a specific order

2009-06-03 Thread Hiero

Had an informative discussion on this at Stack Overflow:

http://stackoverflow.com/questions/936203/storing-sort-order-for-items-held-in-an-habtm-association-cakephp

On Jun 1, 9:31 pm, Hiero  wrote:
> I have a HasAndBelongsToMany association setup on Videos and Bins: A
> Bin can store n references to Videos, and Videos can belong to n Bins.
>
> I need to be able to manually set and store the display order of the
> Videos within a particular Bin (so the client can have his Videos in a
> particular order within the Bin.) My initial thought is to create a
> field in Bin that stores an array of Video IDs in the order they need
> to appear. Is this the most efficient way to handle this?
>
> If so, when I then get the HABTM query result, what is the cleanest/
> most efficient way to re-order the returned query to match the sorted
> array of ID's?
>
> Or is there a better way to achieve what I'm trying to do without
> using HABTM associations?
>
> Thanks in advance -
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



HABTM question - keeping associated records in a specific order

2009-06-01 Thread Hiero

I have a HasAndBelongsToMany association setup on Videos and Bins: A
Bin can store n references to Videos, and Videos can belong to n Bins.

I need to be able to manually set and store the display order of the
Videos within a particular Bin (so the client can have his Videos in a
particular order within the Bin.) My initial thought is to create a
field in Bin that stores an array of Video IDs in the order they need
to appear. Is this the most efficient way to handle this?

If so, when I then get the HABTM query result, what is the cleanest/
most efficient way to re-order the returned query to match the sorted
array of ID's?

Or is there a better way to achieve what I'm trying to do without
using HABTM associations?

Thanks in advance -
--~--~-~--~~~---~--~~
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: HABTM question

2009-05-05 Thread Dave Maharaj :: WidePixels.com

Cool...

Will just leave it the way it is.

Thanks.

Dave 

-Original Message-
From: John Andersen [mailto:j.andersen...@gmail.com] 
Sent: May-05-09 5:57 AM
To: CakePHP
Subject: Re: HABTM question


Hi Dave,

In my opinion, you should only have one HABTM table between the USER and
SYSTEM models. If you need to split your information from the SYSTEM model
into separate presentation steps, do it with views or with additional
tables/models.

Example:
Users <--- systems_users ---> Systems <--- steps_systems ---> Steps ---
> Tasks

where:
Users - contains information on the users.
Systems - contains information on the possible systems.
Steps - contains information on presentation steps within a task.
Tasks - contains information on presentation tasks, for example Hardware,
Software, etc.

and each HABTM table:
systems_users - defines the system that the user is assigned.
steps_systems - defines the system parts that the user may assign in a
specific step within a task.

This could also be made just using views.

The model above may be incomplete, as I do not know all the factors allowing
the user to choose system parts.

Your last question is answered with a No! I would never model it that way!

Hope this helps you on the way,
   John

On May 5, 6:59 am, "Dave Maharaj :: WidePixels.com"
 wrote:
> I have a question about if this is possible or if it even make sense to
do.
>
> I have 4 HABTM tables that are for a USER to select options from. The 
> options are only for choosing and user has no control over any of the 
> actual options (edit delete add none of that) Now the tables look like 
> this:
> TableA
> TableB
> TableC
> TableD
> all have exactly id, name
>
> User
> id
>
> All the HABTM tables are the same for A, B,C, D TableA_Users tableA_id 
> user_id
>
> I have them separate because the User can update their selections on 
> different pages and not all in 1 form.
>
> My question is if I made 1 HABTM table users_options
>
> id
> user_id
> TableA_id
> TableB_id
> TableC_id
> TableD_id
>
> Would it possible to do something like that? If so would the user be 
> able to update TableA options and not mess with other TableX selected
options?
>
> I read about the tree behaviour but have no clue how to use it for 
> what i am interested in using it for.
>
> Dave


--~--~-~--~~~---~--~~
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: HABTM question

2009-05-05 Thread John Andersen

Hi Dave,

In my opinion, you should only have one HABTM table between the USER
and SYSTEM models. If you need to split your information from the
SYSTEM model into separate presentation steps, do it with views or
with additional tables/models.

Example:
Users <--- systems_users ---> Systems <--- steps_systems ---> Steps ---
> Tasks

where:
Users - contains information on the users.
Systems - contains information on the possible systems.
Steps - contains information on presentation steps within a task.
Tasks - contains information on presentation tasks, for example
Hardware, Software, etc.

and each HABTM table:
systems_users - defines the system that the user is assigned.
steps_systems - defines the system parts that the user may assign in a
specific step within a task.

This could also be made just using views.

The model above may be incomplete, as I do not know all the factors
allowing the user to choose system parts.

Your last question is answered with a No! I would never model it that
way!

Hope this helps you on the way,
   John

On May 5, 6:59 am, "Dave Maharaj :: WidePixels.com"
 wrote:
> I have a question about if this is possible or if it even make sense to do.
>
> I have 4 HABTM tables that are for a USER to select options from. The
> options are only for choosing and user has no control over any of the actual
> options (edit delete add none of that)
> Now the tables look like this:
> TableA
> TableB
> TableC
> TableD
> all have exactly id, name
>
> User
> id
>
> All the HABTM tables are the same for A, B,C, D
> TableA_Users
> tableA_id
> user_id
>
> I have them separate because the User can update their selections on
> different pages and not all in 1 form.
>
> My question is if I made 1 HABTM table
> users_options
>
> id
> user_id
> TableA_id
> TableB_id
> TableC_id
> TableD_id
>
> Would it possible to do something like that? If so would the user be able to
> update TableA options and not mess with other TableX selected options?
>
> I read about the tree behaviour but have no clue how to use it for what i am
> interested in using it for.
>
> Dave
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



HABTM question

2009-05-04 Thread Dave Maharaj :: WidePixels.com
I have a question about if this is possible or if it even make sense to do.
 
I have 4 HABTM tables that are for a USER to select options from. The
options are only for choosing and user has no control over any of the actual
options (edit delete add none of that)
Now the tables look like this:
TableA
TableB
TableC
TableD
all have exactly id, name
 
User
id
 
All the HABTM tables are the same for A, B,C, D
TableA_Users
tableA_id
user_id
 
I have them separate because the User can update their selections on
different pages and not all in 1 form.
 
My question is if I made 1 HABTM table 
users_options
 
id
user_id
TableA_id
TableB_id
TableC_id
TableD_id
 
Would it possible to do something like that? If so would the user be able to
update TableA options and not mess with other TableX selected options?
 
I read about the tree behaviour but have no clue how to use it for what i am
interested in using it for.
 
Dave 

--~--~-~--~~~---~--~~
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: complex HABTM question

2009-04-09 Thread Miles J

Use Containable over Recursion.
http://book.cakephp.org/view/474/Containable
--~--~-~--~~~---~--~~
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: complex HABTM question

2009-04-09 Thread luke83
The problem is the attribute recursive: i cannot set it to 3 as i
need! Is there a way to bypass the problem or a trick to have more
deep association fatching?  Thanks!

On 9 Apr, 16:27, luke83  wrote:
> Hi there,
> first question, complex question :D
>
> i have tables in db like this:
>
> + leagues
> | - lid
> | - name
>
> + users
> | - uid
> | - name
>
> + groups
> | - gid
> | - name
>
> + league_staff
> | - lid
> | - gid
> | - uid
>
> The models:
>
> class League extends AppModel {
>     var $name = 'League';
>     var $primaryKey = 'lid';
>     var $hasAndBelongsToMany = array(
>         'Staff' =>
>             array(
>                 'className'              => 'User',
>                 'joinTable'              => 'league_staff',
>                 'foreignKey'             => 'lid',
>                 'associationForeignKey'  => 'lid',
>                 'with'                   => 'LeagueStaff',
>                 'unique'                 => true,
>                 'conditions'             => '',
>                 'fields'                 => '',
>                 'order'                  => '',
>                 'limit'                  => '',
>                 'offset'                 => '',
>                 'finderQuery'            => '',
>                 'deleteQuery'            => '',
>                 'insertQuery'            => ''
>             )
>     );
>
> }
>
> class User extends AppModel {
>     var $name = 'User';
>     var $primaryKey = 'uid';
>
> }
>
> class Group extends AppModel {
>     var $name = 'Group';
>     var $primaryKey = 'gid';
>
> }
>
> class LeagueStaff extends AppModel {
>     var $name = 'LeagueStaff';
>     var $primaryKey = 'gid';
>     var $useTable = 'league_staff';
>     var $hasOne = array(
>         'Group' => array(
>             'className'              => 'Group',
>             'foreignKey'             => 'gid',
>         )
>     );
>
> }
>
> This is what i got:
>
> [leagues] => Array
>                 (
>                     [0] => Array
>                         (
>                             [League] => Array
>                                 (
>                                     [lid] => 1
>                                     [name] => first league
>                                 )
>
>                             [Staff] => Array
>                                 (
>                                     [0] => Array
>                                         (
>                                             [uid] => 1
>                                             [name] => luke83
>                                             [LeagueStaff] => Array
>                                                 (
>                                                     [lid] => 1
>                                                     [uid] => 1
>                                                     [gid] => 1
>                                                 )
>
>                                         )
>
>                                 )
>
>                         )
>                 )
>
> This is what i would like:
>
> [leagues] => Array
>                 (
>                     [0] => Array
>                         (
>                             [League] => Array
>                                 (
>                                     [lid] => 1
>                                     [name] => first league
>                                 )
>
>                             [Staff] => Array
>                                 (
>                                     [0] => Array
>                                         (
>                                             [uid] => 1
>                                             [name] => luke83
>                                             [Group] => Array
>                                                 (
>                                                     [gid] => 1
>                                                     [name] => admin
>                                                 )
>
>                                         )
>
>                                 )
>
>                         )
>                 )
>
> it is like when LeagueStaff is invoked the hasOne attribute is not
> considered
>
> Can someone explain me what i do wrong?
>
> Thanks for time :D
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



complex HABTM question

2009-04-09 Thread luke83

Hi there,
first question, complex question :D

i have tables in db like this:

+ leagues
| - lid
| - name

+ users
| - uid
| - name

+ groups
| - gid
| - name

+ league_staff
| - lid
| - gid
| - uid

The models:

class League extends AppModel {
var $name = 'League';
var $primaryKey = 'lid';
var $hasAndBelongsToMany = array(
'Staff' =>
array(
'className'  => 'User',
'joinTable'  => 'league_staff',
'foreignKey' => 'lid',
'associationForeignKey'  => 'lid',
'with'   => 'LeagueStaff',
'unique' => true,
'conditions' => '',
'fields' => '',
'order'  => '',
'limit'  => '',
'offset' => '',
'finderQuery'=> '',
'deleteQuery'=> '',
'insertQuery'=> ''
)
);
}

class User extends AppModel {
var $name = 'User';
var $primaryKey = 'uid';
}

class Group extends AppModel {
var $name = 'Group';
var $primaryKey = 'gid';
}

class LeagueStaff extends AppModel {
var $name = 'LeagueStaff';
var $primaryKey = 'gid';
var $useTable = 'league_staff';
var $hasOne = array(
'Group' => array(
'className'  => 'Group',
'foreignKey' => 'gid',
)
);
}

This is what i got:

[leagues] => Array
(
[0] => Array
(
[League] => Array
(
[lid] => 1
[name] => first league
)

[Staff] => Array
(
[0] => Array
(
[uid] => 1
[name] => luke83
[LeagueStaff] => Array
(
[lid] => 1
[uid] => 1
[gid] => 1
)

)

)

)
)


This is what i would like:

[leagues] => Array
(
[0] => Array
(
[League] => Array
(
[lid] => 1
[name] => first league
)

[Staff] => Array
(
[0] => Array
(
[uid] => 1
[name] => luke83
[Group] => Array
(
[gid] => 1
[name] => admin
)

)

)

)
)

it is like when LeagueStaff is invoked the hasOne attribute is not
considered

Can someone explain me what i do wrong?

Thanks for time :D

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



HABTM question

2008-11-28 Thread Jerry

I've got a fairly good grasp on the HABTM concept/implementation, but
would like to add a twist:  Suppose we have  users and movies tables.
A user can select 'favorites' from the movies table, as many as he/she
wishes.  So the movies_users table would have an ID, a movie and a
user field.

Now the twist.  What if the user wanted to order the preference the
list of his/her movies?  Would we add a 'preference' or 'order' field
to the HABTM table (movies_users)?  If so, how would that be
implemented in the controller and/or add form?


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



HABTM question. Containable behavior?

2008-06-12 Thread slaphappy

This is how my database structure looks:

Categories HABTM Authors

I have a join table Authors_Categories

Authors HasMany Articles

I want to retrieve all Articles that are in a Category based on the
association with Authors.


Would I use the Containable behavior for this, and if so, what would
the controller look like?


Thanks!

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: General HABTM question

2008-02-23 Thread jim starboard

thanks guv'ner

On Feb 23, 10:48 pm, rtconner <[EMAIL PROTECTED]> wrote:
> You got it right.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: General HABTM question

2008-02-23 Thread rtconner

You got it right.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



General HABTM question

2008-02-23 Thread jim starboard


Despite the naming convention, isn't the HABTM association really just
modeling the shared foreign key table relationship? For example, you
have a 'users' table and an 'items' table, and they are tied together
with the items_users table. Not considering cake, you would use this
because several users could have the same item, or no items, or
multiple items.

Am I missing something?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: HABTM question from newbie

2007-10-04 Thread dardosordi

I don't think that making a model for that join table cause you some
trouble, anyway I see no use of it.

On Oct 4, 12:26 am, Comida411 <[EMAIL PROTECTED]> wrote:
> Rt,
> Can you clarify... I mean the auto create feature is a convenience...
> right...
> The alternative is for me to create the model manually
> Is it bad practice to create models for joins tables comprised soley
> of two foreign keys.. Is that just a bad idea in general?
> Thank you for your time
> T
>
> On Oct 3, 12:20 pm, rtconner <[EMAIL PROTECTED]> wrote:
>
> > Sure why not.
>
> > Cake 1.2 has recenlty added a feature where you can speficy a 'With'
> > association which auto-creates a model for the join table.
> > You may want to mess around with that.
>
> > An example can be found in the OCPHP doc found 
> > here:http://cakephp.org/downloads
>
> > On Oct 3, 8:25 am, Comida411 <[EMAIL PROTECTED]> wrote:
>
> > > There appear to be 3 types of join table in my data model..
>
> > > 1. Pure join - table comprised of two or more foreign keys only and no
> > > other attribues (column headers)
> > > 2. Join as parent - table comprised of two or more foreign keys only
> > > and no other attribues... wherein he table is also the parent to
> > > another table
> > > 3. Join with attributes table comprised of two or more foreign keys
> > > and several other attribues
>
> > > Can I make a rule, that there should be a cake model in cases 2 and 3
> > > but not in case 1
>
> > > Thank you in advance for your response..
> > > [EMAIL PROTECTED] Hide quoted text -
>
> > - Show quoted text -


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: HABTM question from newbie

2007-10-03 Thread Comida411

Rt,
Can you clarify... I mean the auto create feature is a convenience...
right...
The alternative is for me to create the model manually
Is it bad practice to create models for joins tables comprised soley
of two foreign keys.. Is that just a bad idea in general?
Thank you for your time
T

On Oct 3, 12:20 pm, rtconner <[EMAIL PROTECTED]> wrote:
> Sure why not.
>
> Cake 1.2 has recenlty added a feature where you can speficy a 'With'
> association which auto-creates a model for the join table.
> You may want to mess around with that.
>
> An example can be found in the OCPHP doc found 
> here:http://cakephp.org/downloads
>
> On Oct 3, 8:25 am, Comida411 <[EMAIL PROTECTED]> wrote:
>
>
>
> > There appear to be 3 types of join table in my data model..
>
> > 1. Pure join - table comprised of two or more foreign keys only and no
> > other attribues (column headers)
> > 2. Join as parent - table comprised of two or more foreign keys only
> > and no other attribues... wherein he table is also the parent to
> > another table
> > 3. Join with attributes table comprised of two or more foreign keys
> > and several other attribues
>
> > Can I make a rule, that there should be a cake model in cases 2 and 3
> > but not in case 1
>
> > Thank you in advance for your response..
> > [EMAIL PROTECTED] Hide quoted text -
>
> - Show quoted text -


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: HABTM question from newbie

2007-10-03 Thread rtconner

Sure why not.

Cake 1.2 has recenlty added a feature where you can speficy a 'With'
association which auto-creates a model for the join table.
You may want to mess around with that.

An example can be found in the OCPHP doc found here: 
http://cakephp.org/downloads

On Oct 3, 8:25 am, Comida411 <[EMAIL PROTECTED]> wrote:
> There appear to be 3 types of join table in my data model..
>
> 1. Pure join - table comprised of two or more foreign keys only and no
> other attribues (column headers)
> 2. Join as parent - table comprised of two or more foreign keys only
> and no other attribues... wherein he table is also the parent to
> another table
> 3. Join with attributes table comprised of two or more foreign keys
> and several other attribues
>
> Can I make a rule, that there should be a cake model in cases 2 and 3
> but not in case 1
>
> Thank you in advance for your response..
> [EMAIL PROTECTED]


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



HABTM question from newbie

2007-10-03 Thread Comida411

There appear to be 3 types of join table in my data model..

1. Pure join - table comprised of two or more foreign keys only and no
other attribues (column headers)
2. Join as parent - table comprised of two or more foreign keys only
and no other attribues... wherein he table is also the parent to
another table
3. Join with attributes table comprised of two or more foreign keys
and several other attribues

Can I make a rule, that there should be a cake model in cases 2 and 3
but not in case 1

Thank you in advance for your response..
[EMAIL PROTECTED]


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: HABTM Question

2007-06-30 Thread Joshua Benner
You can pass conditions to generateList. Take a look at the api 
.

Ketan Patel wrote:
> Say we have a posts and tags table and the HABTM association has been
> set with posts_tags as the join_table. I am able to save the tags to
> the database. My problem is I know which posts belong to which user
> through the posts table
>
> posts:
> -
> id, user_id, title, details
>
> tags:
> --
> id, name
>
> posts_tags
> -
> id, post_id, tag_id
>
>
> What I want to do, is that when user wants to post a new post, I want
> to show the tags that belongsTo the posts that have been made by user
> and not all the tags. In the posts controller, if I do $this->Post-
>   
>> Tag->generateList() gives me the full list of all tags and I do not
>> 
> want this. Moreover, the sql statement issued for this is :
>
> SELECT `Tag`.`id`, `Tag`.`name` FROM `tags` AS `Tag` WHERE 1 = 1
>
> Should I use $this->Post->findAll(array('Post.user_id'=>$userid)); and
> then fetch the tags from here but does not seem optimal way to do it.
> Please suggest me better solution.
>
> Thanks
> Ketan
>
>
> >
>   


 
-- 
Joshua Benner
http://bennerweb.com


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



HABTM Question

2007-06-29 Thread Ketan Patel

Say we have a posts and tags table and the HABTM association has been
set with posts_tags as the join_table. I am able to save the tags to
the database. My problem is I know which posts belong to which user
through the posts table

posts:
-
id, user_id, title, details

tags:
--
id, name

posts_tags
-
id, post_id, tag_id


What I want to do, is that when user wants to post a new post, I want
to show the tags that belongsTo the posts that have been made by user
and not all the tags. In the posts controller, if I do $this->Post-
>Tag->generateList() gives me the full list of all tags and I do not
want this. Moreover, the sql statement issued for this is :

SELECT `Tag`.`id`, `Tag`.`name` FROM `tags` AS `Tag` WHERE 1 = 1

Should I use $this->Post->findAll(array('Post.user_id'=>$userid)); and
then fetch the tags from here but does not seem optimal way to do it.
Please suggest me better solution.

Thanks
Ketan


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: HABTM question

2007-01-21 Thread c46

Thanks! I don't know what I was thinking!!! I did set to recursive = 2,
but only in a different method and somehow didn't see that it was
missing from the one used here...


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: HABTM question

2007-01-21 Thread Grant Cox

Just set your $recursive to 2, to load two levels of associations
(first level is the Show's Artists, second level is those Artists'
assocations, including their Shows).

$this->Show->recursive = 2;
$show_details = $this->Show->read(null, $your_show_id);

This $show_details will have $show_details[ 'Show' ][ 'Artist' ][ {n}
][ 'Show' ][ {n} ].


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



HABTM question

2007-01-21 Thread c46

Hi,

I'm a newbie at this, and have spent many hours searching and reading
this group. Some answers I found, but some still elude me.

I have the following associations:

Show hasAndBelongsToMany Artist
Artist hasAndBelongsToMany Show

When I 'view' a Show, I can see all the info and also the Artists' info
- which is great!

However, what I also need to do is display the artists' (could be
multiple) other shows as well; and by 'other shows' I mean shows other
than the one currently been viewed. (This info needs to go in a
sidebar.)

How would I go about doing that? Any ideas/suggestions would be great?

Thanks,
Chandan


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Simple HABTM Question

2006-05-26 Thread AD7six

Hi Dee,

The -> Just reverences a Variable or method on an object (if it has ()
it't a method).
In the example above, contractor has a variable Servic, which is set to
a Service object.

It the chain of object could be avoided by using:

var $uses ("Contractor","Service");
$this->Service->find("service_name = 'Web
Design'");

Happy coding, Cheers,

AD7six


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Simple HABTM Question

2006-05-24 Thread Dee

AD7six,
Thanks for this post!  I ran into the same problem as brandags.

I have a question though.  Yes this does work, but why does it work?

I thought the arrow (->) referenced a member of the class like a method
or member.  Is that right?  If so how did Service become a member of
Contractor?   

Can you give a brief explanation?

Thanks,
Dee


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Simple HABTM Question

2006-04-25 Thread brandags

Ha! What do you know - that was it!  Thank you!


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Simple HABTM Question

2006-04-25 Thread AD7six

There´s a reason I wrote "something like" :). I use code very similar
to this, but I wrote it here off the top of my head.

Try:
$result = $this->Contractor->Service->findById($service_id);

Note the lowercase D, I don`t know if that's the reason for the
underscore, but it could be.

Cheers,

AD7six


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Simple HABTM Question

2006-04-25 Thread brandags

Sorry for the double post there.
I also tried querying by the service_name rather than the id, and that
seemed to work better.
I also changed the loop a little bit (because of how I'm grabbing the
data in my view). This seems to work great. (Although, as you
mentioned, it's not sorted)

$result = $this->Contractor->Service->find("service_name = 'Web
Design'");
if ($result['Contractor'])
{
foreach ($result['Contractor'] as $r)
{
$data[]['Contractor'] = $r;
}
$this->set('data', $data);
}
else
{
$this->set('data', Array());
}


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Simple HABTM Question

2006-04-25 Thread brandags

I get a very strange result when I do that. I did have to singularize
the Model names as well:
$result = $this->Contractor->Service->findByID($service_id);

SQL Error in model Service: 1054: Unknown column 'Service.i_d' in
'where clause'

The query that's run is this:
SELECT `Service`.`id`, `Service`.`service_name`
FROM `services` AS `Service`
WHERE (`Service`.`i_d` = 2) LIMIT 1

Why is the 'id' split up like 'i_d'?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Simple HABTM Question

2006-04-25 Thread Brandon Pearce
I get a very strange result when I do that. I did have to singularize the Model names as well: $result = $this->Contractor->Service->findByID($service_id);The query that's run is this:SELECT `Service`.`id`, `Service`.`service_name`
FROM `services` AS `Service` WHERE
(`Service`.`i_d` = 2) LIMIT 1Why is the 'id' split up like 'i_d'?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.  To post to this group, send email to cake-php@googlegroups.com  To unsubscribe from this group, send email to [EMAIL PROTECTED]  For more options, visit this group at http://groups.google.com/group/cake-php  -~--~~~~--~~--~--~---


Re: Simple HABTM Question

2006-04-25 Thread AD7six

Hi Brendon,

Try something like this:

// What do I need to put here to return all the
contractors linked to $service_id?
$result = $this->Contractors->Services->FindByID($service_id);
if ($result)
{
foreach ($result['Contractor'] as $Contractor)
{
$data[] = Array('Contractor'=>$Contractor);
}
$this->set('data', $data);
}
else
{
$this->set('data', Array());
}

This gives me an opportunity to ask a question of my own: There is no
sort order applied at all to the sql for this kind of search - how can
the results be sorted.

Cheers,

AD7six


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Simple HABTM Question

2006-04-25 Thread brandags

I have two tables:

contractors
=
id
first_name
last_name

services
==
id
service_name

Then a table to join them together in a many-to-many relationship:
contractors_services
===
id
contractor_id
service_id

In other words, a contractor can be associated with many services, and
a service can be associated with multiple contractors.

All I want is a list of all the contractors for a particular service.
In regular SQL, the query would look like this:

SELECT c.* FROM contractors c
JOIN contractors_services cs ON cs.contractor_id = c.id
WHERE cs.service_id = 2;
/* Where 2 is the service_id you're looking for */

So, how do I get this to work using the Cake method?
I have tried:
$data = $this->Contractor->findAll('contractors_services.service_id =
'.$service_id);

But it doesn't like that. Look at the query it wrote, it didn't
actually join the services table at all.

Here is my code:
class Contractor extends AppModel
{
var $name = 'Contractor';
var $hasAndBelongsToMany = 'Service';
}

class Service extends AppModel
{
var $name = 'Service'; // required for php4
var $hasAndBelongsToMany = 'Contractor';
}

class ContractorsController extends AppController
{
var $name   = 'Contractors'; // for php4
var $helpers= array('Html', 'Javascript');

function index($service_id='')
{
// What do I need to put here to return all the
contractors linked to $service_id?
$data = $this->Contractor->findAll(); //'service_id = 
'.$service_id);

$this->set('data', $data);
$this->render();
}
}

Can anyone see what I'm doing wrong or what more I need to do to be
able to get this simple query to work?
Thank you,
Brandon


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---