Welcome Guest, Not a member yet? Register   Sign In
Datamapper ORM Multi-tabel Relationship Halp!
#4

[eluser]WanWizard[/eluser]
Datamapper doesn't support multi-relationship joins.

Datamappers expects the combination of the two foreign keys in a relationship table to be unique. If not, you'll get duplicate results when you query that relation.

I suggest you create this table as a separate table like in your example (lets call it purchases). Give it has_one's to user, template and option (and these three a has_many to this table), and use the value a normal data column.

So
Quote:User -> has many -> Purchases
Templates -> has many -> Purchases
Options -> has many -> Purchases
Purchases -> has one -> User
Purchases -> has one -> Template
Purchases -> has one -> User

You shouldn't have any problem with the desired usage:
Code:
$user = new User(1);

// get all this user's purchases
$user->purchase->get();

// get info about a specific purchase
$user->purchase->where('template_id', 16)->get();

// get all users that bought an option
$purchase = new Purchase();
$purchase->include_related('user')->where('option_id', 66)->get();


Messages In This Thread
Datamapper ORM Multi-tabel Relationship Halp! - by El Forum - 07-27-2011, 12:34 PM
Datamapper ORM Multi-tabel Relationship Halp! - by El Forum - 07-28-2011, 02:04 AM
Datamapper ORM Multi-tabel Relationship Halp! - by El Forum - 08-04-2011, 07:18 PM
Datamapper ORM Multi-tabel Relationship Halp! - by El Forum - 08-05-2011, 04:49 AM
Datamapper ORM Multi-tabel Relationship Halp! - by El Forum - 08-05-2011, 08:54 AM
Datamapper ORM Multi-tabel Relationship Halp! - by El Forum - 08-05-2011, 11:37 AM
Datamapper ORM Multi-tabel Relationship Halp! - by El Forum - 08-06-2011, 03:44 AM
Datamapper ORM Multi-tabel Relationship Halp! - by El Forum - 08-06-2011, 04:01 AM
Datamapper ORM Multi-tabel Relationship Halp! - by El Forum - 08-06-2011, 01:27 PM



Theme © iAndrew 2016 - Forum software by © MyBB