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

[eluser]WanWizard[/eluser]
That has indeed to do with the fact that there's a has_many in the chain.

Datamapper uses a single model object to represent the data collection. The collection itself is stored Model as objects in the 'all' array inside the object, and the first element of the array is a reference to $this, it being the first object in the result set.

This means that if you start chaining objects, you chain on the current Model object, not on all objects in the result set. So in your case, ->psu-psuport gives you the psuport of the selected psu object, not of all selected objects.

In the example in the docs, those are has_one relations, so there's only one result possible, which will always be in the current object. Only the last one in the chain can be a has_many.

You can work around it by using include_related:
Code:
$obj->psu->include_related('pduport')->get();
which will include the pduport data in the psu object (columns prefixed with pduport_). This works only with has_one relations.

If you have multiple has_many's in the chain, the only option is to loop over them.

[eluser]North2Alaska[/eluser]
You may also need to be concerned that if you have two pduport records, the query will return two psu rows as well. I've found that it is better to do these kinds of joins in separate queries.

[eluser]WanWizard[/eluser]
That's why I wrote it only works with has_one relations.

[eluser]Ruben.[/eluser]
The documentation is down.

Is there a way to download the documentation for offline usage? Thanks.

[eluser]Damir Sivic[/eluser]
https://bitbucket.org/wanwizard/datamapp...8c1b0c9927

[eluser]WanWizard[/eluser]
[quote author="Ruben." date="1334479898"]The documentation is down.

Is there a way to download the documentation for offline usage? Thanks.[/quote]
Has been fixed, forgot to check all services after server upgrades last night...

[eluser]Ruben.[/eluser]
[quote author="WanWizard" date="1334493154"][quote author="Ruben." date="1334479898"]The documentation is down.

Is there a way to download the documentation for offline usage? Thanks.[/quote]
Has been fixed, forgot to check all services after server upgrades last night...[/quote]

Thanks Smile

[eluser]fima[/eluser]
Hi.
I am using datamapper.
I have one issue.
I have table in db 'events' each event have start_date/end_date/time fields, at first i should render events where('start_date <=' now()) and where('end_date >=' now)with order_by('time') and then i should render future events where('star_date >' now()) with order_by('start_date, time'), all this events i should get in one reguest.
Please give me some advice, how can i do this reguest.

Paul.

[eluser]WanWizard[/eluser]
Simplest answer: two different queries.

You can also do a single query, include the start_date in the order, and deal with the split in your code.

You can also do something complex like "SELECT CASE WHEN start_date <= now() AND end_date >= now() THEN 0 ELSE 1 as futurevent ORDER BY futurevevent ASC, time ASC". You can then use $object->futureevent in your code...

(assuming you're using MySQL)

[eluser]Andy78[/eluser]
Iv noticed that changing the validation error delimiter doesn't seem to be working, it just keep using the p tags. Am I doing something wrong?

Code:
class User extends DataMapper {
  
    // Insert related models that user can have just one of.
var $has_one = array('user_type', 'user_profile');

// Insert related models that user can have more than one of.
var $has_many = array('order');
    
    var $error_prefix = '<span class="input-notification error png_bg">';
    var $error_suffix = '</span>';

    
    public $updated_field = 'field_does_not_exist';
    
    // Optionally, don't include a constructor if you don't need one.
    function __construct($id = NULL)
    {
        parent::__construct($id);
    }




Theme © iAndrew 2016 - Forum software by © MyBB