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

[eluser]WanWizard[/eluser]
DataMapper ORM 1.8.2

Quote:Download the Latest Version Here

View the change log and the upgrade process
Having issues? Please look through the Troubleshooting Guide & FAQs
View the Complete Manual
Search the Manual
(Due to the server's caching configuration, you may need to forcibly refresh your browser to see the changes in the manual.)

DataMapper (DM) is an Object-Relational Mapper that builds on ActiveRecord. Data is loaded from database tables into objects, and relationships can be managed through simple, easy-to-read functions.

To install DataMapper ORM, the (fairly simple) upgrade process is described here.

DataMapper offers these features:
• Everything is an object!
• Easy to setup, easy to use.
• Custom Validation on object properties.
• Lazy Loading (related objects are only loaded upon access).
• Relations and their integrity are automatically managed for you.
• One to One, One to Many, and Many to Many relations fully supported.
• Select data in the style of Active Record (with or without Method Chaining).

You can learn much more from the manual.

----------------------------------------------------------------------

Version 1.8.2:
* New Features
o Backported the DataMapper 2.0 bootstrap to get access to core classes in CodeIgniter version 2.0.3 and above.
o Changed the way watched methods are processed. This allows extensions to replace core methods.
o Add support for an absolute path for "extensions_path".
o Added a all_to_single_array() method to the array extension.
* Bug Fixes
o Added a default for nestedsets root field name as described in the documentation.
o Fixed ignoring model configuration properties with a NULL or FALSE value.
o Fixed broken trans_status() method.
* Other Changes
o Improved the way the available model paths are determined.
o Several corrections to the documentation.

This version introduces a bootstrap loader that needs to be installed in your index.php file, and will allow DataMapper to access CodeIgniters protected core methods and properties, while keeping CodeIgniters core extension mechanism operational (DataMapper does not introduce MY_ versions of libraries).

Make sure to check out the changelog — you won't want to skip this update!

--------------------------------------------------------------------------------

Bug reports and feature requests:

DataMapper has moved to Github for the development of version 2.0. Please use the issue register / bug tracker on github to report new bugs or for new feature requests. If you do, please include in your description is link to the thread on this forum discussing the issue (if possible), so I have a link between the two and can keep track of all issues.

--------------------------------------------------------------------------------

Older Discussions: Version 1.8.1, Version 1.8.0, Version 1.7.1, Version 1.6.2, Version 1.5.4, Version 1.5.3 and older.

Thanks goes to Overzealous, for all he has achieved with DMZ. And to stensi, for providing such an amazing code base to work on.
#2

[eluser]Spir[/eluser]
[quote author="Spir" date="1322848883"]Hi,
I'm here again with my many to many relationship noobs question.
What is the best way to load join field when iterating on items.
Here are the models :

Code:
class Items extends DataMapper {
    public $has_many = array(
        'lang' => array(
            'class' => 'lang',
            'other_field' => 'item',
            'join_self_as' => 'item',
            'join_other_as' => 'lang', would be 'lang_id'
            'join_table' => 'items_langs'
),
    );
}


Code:
class Langs extends DataMapper {
    public $has_many = array(
        'item' => array(
            'class' => 'item',
            'other_field' => 'lang',
            'join_self_as' => 'lang',
            'join_other_as' => 'item', would be 'item_id'
            'join_table' => 'items_langs'
),
    );
}

Now I'm loading all items and looping on them. I want to display their data and the field "name" which is a data in the joined field (ie. in the table items_langs).

I have loaded my current language and I want to display the name of the item in my language. What is the best way to do it?

Code:
$items = new Item();
$items->get();

foreach($items as $item)
{
    $item->lang->where('id', $default_language->id)->include_join_fields()->get();
    echo $item->lang->join_name;
    // Would be nice to pass related field as param like this :
    $item->include_join_fields($default_language)->get();

}
Lang is already loaded why loading it again? Any better solution?[/quote]
Ok some update. I did pause that project and now I'm back on it. There is one things that I made wrong with that code that keep me scratching my head for some time. Don't use lang as a model name Smile
and RTFM! Tongue
http://datamapper.wanwizard.eu/pages/reservednames.html

The error I had was :
Unable to call the method load

Just in case someone stumble on this…
#3

[eluser]Mark Price[/eluser]
Is there a way to reference a specific record in the Datamapper query results?

For example I have a Datamapper instance that has already queried and is storing all of the table records. Now I want to reference this Datamapper instance for a specific record by the record id without having to query the database again.

Is this possible?
#4

[eluser]WanWizard[/eluser]
If you have "all_array_uses_ids" in your config set to TRUE, you can access the records in the resultset using
Code:
$myrec = $model->all[$id_your_looking_for];
you can access by id only though. In all other situations you'll have to iterate over the object to find it.
#5

[eluser]Mark Price[/eluser]
[quote author="WanWizard" date="1326958553"]If you have "all_array_uses_ids" in your config set to TRUE, you can access the records in the resultset using
Code:
$myrec = $model->all[$id_your_looking_for];
you can access by id only though. In all other situations you'll have to iterate over the object to find it.[/quote]

Thank you WanWizard, that is exactly what I was looking for.
#6

[eluser]Unknown[/eluser]
I ran into problems with this line of code:

Code:
$object->where_in('id', $ids)->get();

$ids is an array. When it has more than one element it works perfectly, but when it only has one element the query isnt executed. Is this behavior wanted?
#7

[eluser]WanWizard[/eluser]
Datamapper uses CI's where_in method (_where_in in DB_Active_Rec to be exact), and simply passes the table name, field name and array to it.

I've looked at that code too, but I can't see why it would fail on an array with one element.

Tried this in my test environment (latest DM, CI 2.0.2), without problems:
Code:
$table1 = new table1();
$table1->where_in('id', array('1'))->get();
var_dump($table1->all_to_array());
#8

[eluser]Mark Price[/eluser]
I'm trying to figure out how I can query results using the relationship id of a record in the join table.

The documentation gives an example similar to the one below:
Code:
$alarm = new Alarm();
$alarm->where_join_field('user', 'id', 1)->get();

But this does not add the JOIN statement to the join table in the SQL query. Only the WHERE clause.

Then I gave the following a try:

Code:
$alarm = new Alarm();
$alarm->include_related('user', 'id')
    ->where_join_field('user', 'id', 1)
    ->get();

The problem with this is that include_related() aliases the table names and the new alias is not used in the WHERE clause causing column 'id' not to be found.

Any ideas how I would go about this using the relationship id?

Thank you
#9

[eluser]WanWizard[/eluser]
The idea behind where_join_field() is that it allows you to filter relations based on a join_field, so a non-key column in your relationship table. This only works if you're actually querying a relation, and therefore the method only adds a WHERE clause, and assumes the JOIN is already there.

If you want to query on a related object value, you would use
Code:
$alarm = new Alarm();
$alarm->where_related_user('id', '1')->get();


DataMapper is smart enough to detect that this is a foreign key in the relationship table, and only join that table.
#10

[eluser]Unknown[/eluser]
Is there a way to accomplish some kind of where_related_count type query on deep relationships?

I have Categories, which have many Templates. Templates can have many Procedures. I want to return all the categories that have at least one related Procedure.

This doesn't work, but I'm trying to create a query along these lines:

Code:
$categories = new Category();
$categories->include_related_count('template/procedure')->get_iterated();
foreach($categories as $category)
{
    if($category->template_procedure_count > 0)
    {
        // Save this category for output later
    }
}




Theme © iAndrew 2016 - Forum software by © MyBB