Welcome Guest, Not a member yet? Register   Sign In
DataMapper ORM v1.8.2

[eluser]WanWizard[/eluser]
[quote author="coldscooter" date="1337104326"]If i set up a relationship in one model (lets say users relates to access_logs), can I then create new records in access_logs through the User model, without having a model for access_logs?
[/quote]
No, you need a model for every table, except for relationship tables that only contain foreign keys.

[eluser]WanWizard[/eluser]
[quote author="coldscooter" date="1337118686"]Can i set up a relationship without having a separate relationship table?[/quote]
Yes, every relationship except for a many-to-many. Just add the foreign key to the other table.

[eluser]ahmetkapikiran[/eluser]
Hi,
Tables

Upload Fields
Code:
id|user_id|link|status

Upload_acc Fields
Code:
id|user_id|name|password


Upload Acc Model
Code:
var $table = 'Upload';
        var $has_one = array(
        'Upload_acc'=>array('class'=>'Upload_acc','other_field'=>'upload','join_table'=>'Upload_acc'),
        );

How do I make this query with dm?

Code:
SELECT * FROM Upload JOIN Upload_acc ON Upload.user_id = Upload_acc.user_id WHERE Upload.status=0

[eluser]WanWizard[/eluser]
You can not, Datamapper only joins on primary key => foreign key, as that defines the relation.

Your table design is quite weird, and not normalized, so check that out first.

Also, your relation definition is odd, you have a model that uses itself as join table?

[eluser]coldscooter[/eluser]
After saving a new object using DataMapper, when I view the object after the save, I only see the new id that the database has auto generated, and not other fields that are in the newly generated db record.

Is there a way to see the updated fields without running a separate get()?


[eluser]WanWizard[/eluser]
What do you mean?

How can data be created in the database without it being present in the object? If you have defined defaults in your table definition, don't.

Instead, have the model fill in the defaults for you using validation rules.

[eluser]coldscooter[/eluser]
[quote author="WanWizard" date="1337193399"]What do you mean?

How can data be created in the database without it being present in the object? If you have defined defaults in your table definition, don't.

Instead, have the model fill in the defaults for you using validation rules.[/quote]

I mean if you are using CURRENT_TIMESTAMP, or any other default values. It is a shame that I have to define all default values in the model.

It would be cleaner to not need to define these things in the model if they already exist in the schema? Unless this is a performance consideration...

Because I thought a key goal of DataMapper is to remove the need the hardcode your schema into your models.


[eluser]WanWizard[/eluser]
You don't have to, but they you'll have to re-read the record after the insert (or update). You were the one complaining that after an insert the object is out of sync with the record.

Point is that you can't have the cake and eat it. Datamapper isn't clairvoyant, it has no way of knowing what the database engine decides to on it's own.

Your insert or update could have a linked trigger, which updates all other records currently loaded by Datamapper. And it would be none the wiser.

If you have an idea on how to solve this dilemma, I'm all ears...

[eluser]coldscooter[/eluser]
I agree, there is no way to do this without retrieving the record from the database after the save has been made, which is a little inefficient.

Btw, I really love the library.

[eluser]weboap[/eluser]
hey @WanWizard i installed the datamapper lib with a fresh CI reactor and got an error, look like in the change log they renamed system/databse/DB_active_rec.php to DB_query_builder.php and the class CI_DB_active_record to CI_DB_query_builder. i tought of reporting it here as it affect third_party/datamapper/system/DB.php for future versions. as the official CI Version still come with the old name.




Theme © iAndrew 2016 - Forum software by © MyBB