Hello grigri,

I've tested your solution : when I just save an Article with it's
complements, that's work fine.
But if I save other Articles linked models, there is a problem: in the
join table "articles_articles" the other models ids are added!

Example:

Articles HABTM Articles (article_id1, article_id2)
Articles HABTM Tags (article_id, tag_id)
Articles HABTM Feeds (article_id, feed_id)

In a form, when I create an Article, I can select zero or more
Articles to complete my new article, zero or more Tags and zero or
more Feeds.
If I select one or more Articles and zero Tags and zero Feeds, that's
work fine: the new id and all articles ids are saved correctly in my
join table "articles_articles".
But if I select one or more Articles AND (one or more Tags OR one or
more Feeds), Tags ids or Feeds ids are saved in the join table too...

Must I use "unbind" before saving to avoid this issue?

Hope this post is clear...

BR

Avairet

On 29 fév, 13:59, avairet <[EMAIL PROTECTED]> wrote:
> OK, great!
>
> Thank you so much. I try this stuff now.
>
> On 29 fév, 13:52, grigri <[EMAIL PROTECTED]> wrote:
>
> > Nonono, the 'ReadTheseFirst' and 'ReadTheseAfter' are aliases for the
> > same model - Article. You don't need to create any more model files.
>
> > For the form side of things, it will be as per normal :
>
> > <?php
> > echo $form->input('ReadTheseFirst.ReadTheseFirst', array('multiple' =>
> > 'checkbox')); // Or however you normally do things
> > ?>
>
> > On Feb 29, 12:24 pm,avairet<[EMAIL PROTECTED]> wrote:
>
> > > Ok, an only one question: must I create the "ReadTheseFirst" and
> > > "ReadTheseAfter" model files?
> > > In other words, in a form how indicate the data[] array?
>
> > > On 29 fév, 12:48, grigri <[EMAIL PROTECTED]> wrote:
>
> > > > You can give them any aliases you like, but they must be distinct
> > > > (different from each other AND from the 'Article' model name).
>
> > > > You can also rename the field names, just make sure you change the
> > > > keys in the association too - in the right order!
>
> > > > On Feb 29, 11:14 am,avairet<[EMAIL PROTECTED]> wrote:
>
> > > > > OK thank you grigri!
>
> > > > > I will try your solution, but is it your naming obligatory for aliases
> > > > > (ReadThese...) and field's names?
>
> > > > > On 29 fév, 12:07, grigri <[EMAIL PROTECTED]> wrote:
>
> > > > > > Try this:
>
> > > > > > join table "articles_articles" : article1_id and article2_id
>
> > > > > > class Article extends AppModel {
> > > > > >   var $hasAndBelongsToMany = array(
> > > > > >     'ReadTheseFirst' => array('className' => 'article', 'joinTable' 
> > > > > > =>
> > > > > > 'articles_articles', 'foreignKey' => 'article1_id',
> > > > > > 'associationForeignKey' => 'article2_id'),
> > > > > >     'ReadTheseAfter' => array('className' => 'article', 'joinTable' 
> > > > > > =>
> > > > > > 'articles_articles', 'foreignKey' => 'article2_id',
> > > > > > 'associationForeignKey' => 'article1_id')
> > > > > >   );
>
> > > > > > }
>
> > > > > > On Feb 29, 10:56 am,avairet<[EMAIL PROTECTED]> wrote:
>
> > > > > > > Hi Adam and thank you for answer,
>
> > > > > > > My schema :
>
> > > > > > > Table "articles" with "id" and "title" fields.
> > > > > > > My reflexive association:
> > > > > > > - an article complete n:m articles
> > > > > > > - an article is completed by n:m articles
>
> > > > > > > Is that clear?
>
> > > > > > > On 29 fév, 11:46, Adam Royle <[EMAIL PROTECTED]> wrote:
>
> > > > > > > > I am sure this is possible, you just need to use aliases and set
> > > > > > > > custom join keys. What data are you modelling? It might be 
> > > > > > > > easier to
> > > > > > > > give an example if you tell us your schema.
>
> > > > > > > > Cheers,
> > > > > > > > Adam
>
> > > > > > > > On Feb 29, 8:26 pm,avairet<[EMAIL PROTECTED]> wrote:
>
> > > > > > > > > Hello, I resend this discussion because I've tested your 
> > > > > > > > > solution and
> > > > > > > > > it doesn't work...
>
> > > > > > > > > So is there anybody to help me to create a "reflexive 
> > > > > > > > > association"? A
> > > > > > > > > table HABTM itself?
> > > > > > > > > e.g. : an Article is completed by 0 or N Article and inversely
>
> > > > > > > > > BR
>
> > > > > > > > > On 14 fév, 01:25, "b logica" <[EMAIL PROTECTED]> wrote:
>
> > > > > > > > > > On Feb 13, 2008 8:00 AM,avairet<[EMAIL PROTECTED]> wrote:
>
> > > > > > > > > > > Hello,
>
> > > > > > > > > > > Thank you for answer.
>
> > > > > > > > > > > No I haven't tried this, because I thought Cake doesn't 
> > > > > > > > > > > accept an
> > > > > > > > > > > association between 2 models with the same name...
> > > > > > > > > > > In your example, have you created the "joinTable" before 
> > > > > > > > > > > creating
> > > > > > > > > > > HABTM in the model definition?
> > > > > > > > > > > Is it possible to link YourModel with YourModel and to 
> > > > > > > > > > > have
> > > > > > > > > > > "foreignKey" and "associationForeignKey" with the same 
> > > > > > > > > > > name?
>
> > > > > > > > > > I have no idea. That was just the first thing that occurred 
> > > > > > > > > > to me. Try
> > > > > > > > > > it and see.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to