Welcome Guest, Not a member yet? Register   Sign In
Multi table Datamapper Relationship
#1

[eluser]Unknown[/eluser]
Hi,

I actually have a rating system for a house in such way that a user can rate different houses and a house can have many ratings from differents users.
So there is a joining table houses_ratings and the actual models

User

class User extends DataMapper {

public $table = 'users';
public $has_many = array(
'house'

,'rating'=>array(
'class'=>'house'
,'other_field'=>'rate'
,'join_self_as'=>'user'
,'join_other_as'=>'house'
,'join_table'=>'houses_ratings'
)


class House extends DataMapper {

public $table = 'houses';
public $has_one = array('user');
public $has_many = array(


,'rate'=>array(
'class'=>'user'
,'other_field'=>'rating'
,'join_self_as'=>'house'
,'join_other_as'=>'user'
,'join_table'=>'houses_ratings'
)

Actual table houses_ratings looks like

id house_id user_id rating

My problem is that i would like to introduce differents concepts for rating a house not just a general one, for example cleaning, situation, etc...

So i created a table Concepts
id | concept
1 cleaning
2 situation

and i included the field concept_id to the table houses_ratings

id | house_id | user_id | concept_id | rating

I am newbie and i don't know if that is the correct aproach.

I should now create a concept model and relate it to house and user model or only relate it to house model?

Also i realised the set_join_field returns the actual query

UPDATE `houses_ratings` SET `rating_id` = 3 WHERE `house_id` = 1 AND `user_id` = 1

How i manage to set the query as

UPDATE `houses_ratings` SET `rating_id` = 3 WHERE `house_id` = 1 AND `user_id` = 1 AND 'concept_id' = 2


Thank you for your help
#2

[eluser]WanWizard[/eluser]
Datamapper doesn't support three-way relations, a junction table is always between two tables.
#3

[eluser]Unknown[/eluser]
Thank you !

So waht's the best aproach to acomplish the desired result of having diferents kinds of concepts to rate a house by many users?

Is it possible to join a table (concepts) with an actual joined table houses_ratings?

or what will be the correct structure?

thank you for your patience...







Theme © iAndrew 2016 - Forum software by © MyBB