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

[eluser]WanWizard[/eluser]
Ok. I misunderstood you.

In that case you need a many-to-many between Purchase and Option, and a relationship table called options_purchases, with 'id', 'option_id' and 'purchase_id'.

And you should store the value in that relationship table (as a join_field), since it's a property of the relation, and not of the purchase.

Code:
the purchases table:
[id] [user_id] [template_id]
  1       1         1
  2       2         7

the options_purchases table:
[id] [purchase_id] [option_id] [value]
  1        1            1        Arial
  2        1            2        Blue
  3        1            3        California
  4        2            1        Helvetica
  5        2            3        Hawaii
  6        2            5        Center
  7        2            6        Sunflowers

You can than access the purchases of a user by using
Code:
// load a user
$user = new User(1);

// get all the users purchases
$user->purchase->get();

// loop through the purchases
foreach ($user->purchase as $purchase)
{
    // get the template purchased
    $purchase->template->get();

    // get all purchased options including the option value
    $purchase->option->include_join_fields()->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