• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DataMapper 1.6.0

[eluser]introvert[/eluser]
Hello,

I have 2 simple models with has_one relation:

Code:
class Feed extends DataMapper {
    var $has_many = array('item');

    function __construct() {
        parent::DataMapper();
    }
}

class Item extends DataMapper {
    var $has_one = array('feed');

    function __construct() {
        parent::DataMapper();
    }
}

When I want to relate those 2 records:

Code:
$f = new Feed();
$f->save();
$i = new Item();
$i->save();
        
$f->save($i);

I get error that items_feeds table doesnt exist. Why would DM require additional table if there is has_one relation? If I try removing has_many from Feed model, I get the same result.

What am I doing wrong? Should I pass any additional data to DM in such cases?

Thanks in advance!

[eluser]BrianDHall[/eluser]
I don't think Datamapper supports in table foreign keys, so every relation amongst two tables must have its own join table.

Check out Overzealous Extension to Datamapper for support of in-table foreign keys, which eliminate the need for join tables in cases of has_one relationships.

[eluser]ennis[/eluser]
I was wondering How I would go about this with datamapper,

I have a clients table and a clients_clients table that links a client as a child of another clinet (id, parent_id, child_id)

But it doesnt seem to work, can datamapper models relate to them selfs?

I have jst had a look under the advanced relationshops section still a bit confused though

Sorry if what i write seems confusing Smile

Cheers.

[eluser]OverZealous[/eluser]
@ennis
I hate to keep repeating myself, but if you want more advanced features (such as self relationships), you should switch to using DMZ, my extended version of DataMapper.

The discussion board is available in my signature, and you can learn a lot more about it from the link above.

[eluser]ennis[/eluser]
Was just about to post Smile

var $has_many = array(
'relatedclient' => array(
'class' => 'client',
'other_field' => 'client'
),
'client' => array(
'other_field' => 'relatedclient'
)
);

Thanks you I figured it out was already using DMZ thanks

[eluser]Benedikt[/eluser]
Hi,
As far as I understood everything is an object.

So if I have a car (table: cars) and this car has a color (table: colors) I have two models, a car model and a color model, right?

So let's say my car has a lot more attributes, e.g. what kind of tyres, what kind of radio, what kind of seats etc, I have also the tables "tyres", "radios", "seats" etc, right?

So let's assume I want to bundle these attributes and set a prefix only for the car's attributes. How can I do this?

I want to have the "main objects" like "car" without any table-prefix. But attributes should be with a prefix. I know how to set a join-prefix and a table-prefix for certain models. Then I can also set the table name für "plurals". Could I do the following to realize the grouping (same prefix for the car's attributes):

Color-Model:
$table = 'car_colors';
$prefix = '';
$join_prefix = 'join_';

Car-Model:
$table = 'cars';
$prefix = '';
$join_prefix = 'join_';

etc.

Would that work?

Thanks for your help!!!

[eluser]Benedikt[/eluser]
Sorry for spamming this thread, but is Datamapper still under active development, e.g. update to more recent versions of CodeIgniter if necessary?

[eluser]Unknown[/eluser]
I'm studying any Codeigniter ORM, is this project still active ?
Thanks in advance.

[eluser]Mitja B.[/eluser]
HI,

can you please tell me benefits of DMZ DataMapper against Doctrine? Why i should use DMZ Datamaper instead of Doctrine?

[eluser]BaRzO[/eluser]
[quote author="OverZealous" date="1255624505"]@ennis
I hate to keep repeating myself, but if you want more advanced features (such as self relationships), you should switch to using DMZ, my extended version of DataMapper.

The discussion board is available in my signature, and you can learn a lot more about it from the link above.[/quote]

Follow this


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.