tags:

views:

72

answers:

1

I have four tables

Tag=>id,tag_name

Image=>Id,Image_name

TagImage=>Id,tag_id,Image_id


ImageStudent=id,Image_id,student_id

And I want to find a record using student id and tag name. What relationship do I use?

A: 

Might be better to use a UNION with a query like this, here it is with the necessary joins.


SELECT Image.* FROM Image 
INNER JOIN ImageStudent ON Image.Id = ImageStudent.Image_id
LEFT OUTER JOIN TagImage ON Image.Id = TagImage.Image_id
INNER JOIN Tag ON TagImage.Id = Tag.Id
WHERE Tag.tag_name = 'foo' AND ImageStudent.student_id = 42;

mmattax
All things are perfectly nice? Thanks Can u tell me in details of referential integrity??what is that?
dilip
I create model help of your answer sir but it not working ..!can hu explain me in details how HABTM relationship gibven in model ...plz
dilip
You need to be a lot more specific with your questions, you're making this sound like it's your homework... You can get clues to the relationships by the JOINS I used in the query (OUTER vs. INNER)
mmattax
Tag=>id,tag_nameImage=>Id,Image_nameTagImage=>Id,tag_id,Image_idImageStudent=id,Image_id,student_idStudent = id ,fname ,lname,Given by your query its work but not give right result..?Can help how i join above table ?i want to find image by using tag_name and student_id
dilip
To mmattax sirI want to create taging system tag on photo and also tag on image using student id how i create database table and how i handle relationship in cakephp plz sir help me ........plzthanks
dilip