Monday, December 1, 2008

Re: Saving data in HABTM relation ship

First I would suggest setting your debug to '3' in core.php so you can
see the SQL that is getting generated to do your updates.

Second, let me see if I understand. Somewhere in your
teachers_controller.php, you are trying to save the data for a
Teacher, and the related Tags.

From your HATBM description, the Tags that are related to a Teacher
are found in the entities_tags table by entity_id (which maps to the
teacher_id when entity_type_id = 1?).

Are you having trouble getting the entity_type_id into the
entities_tag table? I would think you would just need to set your
entity_type_id in the data model in the $this->Teacher->EntityType if
you have the correct HABTM set up:

1) teachers HABTM Tag and Entities

var $hasAndBlongsToMany = array(
'Tag' => array(
'className' => 'Tag',
'joinTable' => 'entities_tags',
'foreignKey' => 'entity_id',
'associationForeignKey' => 'tag_id',
'conditions' => 'entity_type_id = 1'
),
'EntityType' => array(
'className' => 'EntityType',
'joinTable' => 'entities_tags',
'foreignKey' => 'entity_id',
'associationForeignKey' => 'entity_type_id'
)
)

2) tags HABTM Teachers
3) Others ?

On Dec 1, 7:50 am, bookme <rarockthewo...@gmail.com> wrote:
> Hi,
>
> I have a problem to saving data in HABTM relation ship.
>
> 1) tags : tag_id, tag_name .
> 2) entity_types : entity_type_id, entity_type_name .   [(0, Posts),
> 3) teachers : teacher_id, teacher_name .
> 4) entities_tags : tag_id, entity_type_id, entity_id .
>
> I am using HABTM relation ship between Tag and Teacher modal
>
> *Teacher Model*
> <?php
> class Teacher extends AppModel {
>
>     var $name = 'Teacher';
>
>     var $hasAndBelongsToMany = array(
>             'Tag' => array (
>                 'className' => 'Tag',
>                 'joinTable' => 'entities_tags',
>                 'foreignKey' => 'entity_id',
>                 'associationForeignKey' => 'tag_id',
>                 'conditions' => 'entity_type_id = 1'
>             )
>     );
>
> }
>
> ?>
>
> here 'entity_id', 'tag_id' is saving in database tabel
> 'entities_tags'  but 'entity_type_id  is not saving. here it's always
> default value 0 is saving but it must be save1.
>
> Please tell me where should I define 'entity_type_id  = 1  other than
> relation ship so that it can be save.
>
> or is there any solution so that I can be save one extra filed
> 'entity_type_id  in database with  'entity_id' , tag_id?
>
> 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 cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: