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

[eluser]tarciozemel[/eluser]
[quote author="WanWizard" date="1333528310"]
The two objects you saved, where they new objects (not present in the database) or existing objects?
[/quote]New objects.


[quote author="WanWizard" date="1333528310"]
And if you do
Code:
if ( ! $this->save($company))
{
    // stuff
}
without the save() of $company first, will it be related correctly?
[/quote]
No, both company record and the relationship aren't created.


[quote author="WanWizard" date="1333528310"]
And which version of Datamapper do you use? The latest from bitbucket or one of the distributions?
[/quote]
1.8.2 from Bitbucket.

[eluser]WanWizard[/eluser]
Ok. I'll try to find some time to debug this. Life's pretty hecktic at the moment...

[eluser]Colm Ward[/eluser]
Hi Wanwizard

I have a new project which has to run on a Windows server, starting with a MySQL database, and has to move to a MSSQL database in about a year. I don't like these conditions at all but there is nothing I can do about it, the decision is outside my control and has to do with support and availability of DBAs etc. However I am still hoping to use Datamapper ORM as I've found it very useful in the past.

I notice that the latest version of CI (2.1.0) includes PDO support. So in theory that means that I could develop in CI+Datamapper on MySQL, and then in a years time migrate the database, switch the PDO driver in CI from mysqli to mssql, and everything should work. Right?

Ok I realise it's probably not something that has been tried much or documented. I already know that there will be some queries that will have to be rewritten by hand due to the different flavours of SQL. I guess I'm just looking for any useful advice!

cheers,
Colm

[eluser]WanWizard[/eluser]
Datamapper doesn't have it's own database layer, it uses CI's Active Record to interact with the database. So it supports whatever CI supports in terms of RDBMS platforms.

I've never used CI in other then MySQL environments, so I can't comment on how good CI is with MSSQL.

It also depends a bit on the version of MSSQL. It uses Transact SQL, which is a dialect different from MySQL, which has some language constructs missing that are often used. In particular LIMIT and OFFSET. I'm not sure CI can emulate that. If not, you're out of luck because Datamapper requires them in a lot of situations.

I know the latest release(s?) do support LIMIT and OFFSET, so you don't have to craft your own TOP queries anymore.

[eluser]AAtticus[/eluser]
I have two simple classes with a ONE - TO - ONE relationship.
When I save one class, I want to automatically create the related class and save the relationship.

So my code is something like this:

Code:
...
$x = new X();
$x = from_array($this->input->post());

$y = new Y();

if($x->save($y)) {
//
}

When i use $x->save(y) $x is saved but the relationship isn't, neither is $y.
When i use $y->save(x) I get this error: You must use the "set" method to update an entry.

[eluser]WanWizard[/eluser]
There seems to be an issue with saving relations on unsaved objects. I haven't had time to look at it.

Try saving Y first:
Code:
if ($y->save())
{
    if($x->save($y))
    {
    }
    else
    {
        // save X failed
    }
}
else
{
   // save Y failed
}

[eluser]DocO[/eluser]
Not sure if this is addressed somewhere, but couldn't find it. It may be an architectural problem of my own, or a misunderstanding.

I'm using 1.8.2, and I have a one-to-one relationship between ObjectA and ObjectB. The relationship is defined via $has_one in both models, and in the table ObjectA has an "objectb_id" field.

I'm not sure where enforcement of the one-to-one relationship should be applied and how. Right now, I can save two different instances of ObjectA, with the same relationship to one instance of ObjectB, and that shouldn't happen.

Right now I'm using CodeIgniter's form validation, mainly because that is what I used before It used DataMapper, and I have a few custom functions. Do I need to move to DataMapper's object validation instead? And if so, do I need to write a custom validation? Or is "unique_pair" what I want (as in, using "unique_pair" => "objectb_id" or something like that)?

[eluser]WanWizard[/eluser]
has_one means that the object has a relation with either zero or one other object.

As Datamapper doesn't track the other side of the relationship (could be a has_one or a has_many), it currently doesn't track or enforce anything. You'll have to code that yourself.

It would require a full view of the relationship, and the introduction of a belongs_to relation, to deal with this properly.

This is on the roadmap for 2.0 (no ETA yet).

[eluser]DocO[/eluser]
Hrm...so I started the changeover to using DataMapper's validation. However, it is ALWAYS failing validation, even when I don't have a validation array defined! And $object->error->string does not appear to contain any errors!

The model of the object is just the basic constructor. Here is a code snippet from the controller, in a "save() function:

Code:
$object = new Psu();

                $object->slug = url_title($this->input->post('name'), 'dash', TRUE);
                $object->name = $this->input->post('name');
                $object->descr = $this->input->post('descr');
                $object->device_id = $this->input->post('device');
                $object->pduport_id = $this->input->post('pduport');

                if ($object->save) {
                        $this->session->set_flashdata('message',"Device Power Supply $object->slug (id $object->id) has been saved.");
                        redirect('psus/edit/'.$object->slug);
                } else {
                        # Save the errors
                        $errorstring = $object->error->string;
                        echo "ERROR: $errorstring\n";
                }

The end result is that "ERROR:" will print, but nothing else.

[eluser]WanWizard[/eluser]
Don't you mean
Code:
if ($object->save()) {
instead of
Code:
if ($object->save) {
?

In development, ALWAYS enable all error reporting. You would have picked up the notice error informing you that $object->save does not exist.

And because it doesn't exist, it evaluates to false, causing the error to be printed all the time.




Theme © iAndrew 2016 - Forum software by © MyBB