Wednesday, December 3, 2008

Re: save extra filed 'entity' in HABTM join tabel

Thanks Rob,

I tried your solution but I am using tag behaviour for inseritng tag
by beforeSave function so I can not get entity_id that's blog's tabel
id (blog_id) in beforeSave function.

So your suggest solution is not working.

Multiple tags and entity_id is successfully inserting into
entites_tags tabel without use of EntitiesTag module.

Is there any other solution for saving one extra filed 'entity' ?

Should I use custom query solution for this If cake can not provide me
a better solution?

Please help me.

Thanks

On Dec 4, 9:30 am, Rob <webwe...@gmail.com> wrote:
> If I get this correctly, you want to update the related entities from
> the blogs_controller, then you need to set the associated data by
> referencing it properly.
>
> The saveAll should handle this OK for you as long as you are setting
> the data the way you stated.
>
> You could also manually do thesavefor thejointable by doing a
> separatesaveafter you do yoursavefor the Tag:
>
> // for the 'add' action ...
>
> $this->Tag->create();
> if ($this->Tag->save($this->data)){
> $this->data['Tag']['tag_id'] = $this->Tag-
>
> >getLastInsertId();
>
> $this->data['EntitiesTag']['tag_id'] = $this->data
> ['Tag']['tag_id'];
> $this->data['EntitiesTag']['entity'] = 1;
>
> $this->Tag->EntitiesTag->create();
>
> // Thensavethe EntitiesTag ...
> if ($this->Tag->EntitiesTag->save($this->data
> ['EntitiesTag'])) {
> $user_slot_id = $this->User->UserSlot-
>
> >getLastInsertId();
>
> On Dec 2, 11:24 pm, bookme <rarockthewo...@gmail.com> wrote:
>
> > Hi,
>
> > I am trying this from last three days but can not solve
> > problem...Please help me to find a solution to this problem.
> > I want tosaveaextrafield inHABTMJointabel.
>
> > 1) tags : tag_id, tag_name .
> > 3) blogs : id, title, body
> > 4) entities_tags : tag_id,entity, entity_id .
>
> > I am usingHABTMrelation ship between Tag and Blog modal
>
> > *Blog Model*
> > <?php
> > class Blog extends AppModel {
>
> > var $name = 'Blog';
>
> > var $hasAndBelongsToMany = array(
> > 'Tag' => array('className' => 'Tag',
> > 'joinTable' => 'entities_tags',
> > 'foreignKey' => 'entity_id',
> > 'associationForeignKey' => 'tag_id',
> > 'with' => 'EntitiesTag',
> > 'unique' => true,
> > 'conditions' => 'EntitiesTag.entity= 1',
> > ),
> > );
>
> > }
>
> > ?>
>
> > entity_id, tag_id is saving in database successfully butentityis not
> > saving intabel.
>
> > I tried following solution for this in blogs_controller
>
> > 1 $this->data['EntitiesTag']['entity'] = 1
>
> > 2 $this->data['EntitiesTag'][0]['entity'] = 1
>
> > 3 I read one tutorialhttp://teknoid.wordpress.com/2008/09/24/saving-extra-fields-in-the-jo...
>
> > I tried it but not successed.
>
> > It would be gr8 for me if somebody tell how can Isavethisextra
> > field 'entity' intoJointabelentites_tags ?
>
> > Is there missing something or doing wrong?
--~--~---------~--~----~------------~-------~--~----~
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+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: