Welcome Guest, Not a member yet? Register   Sign In
[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition)

[eluser]OverZealous[/eluser]
1) Is it saving any relationships?

2) Does $b->save($d) work?

3) Are you able to save brainstorms manually, without the HTML form / submit?

4) Are you certain that $model and the $has_many item are spelled the exact same, on both models? I know you said you looked, but make sure there aren't any typos. Also, this assumes you are using standard, simple relationships, not the advanced relationships.

5) Have you tried outputting the queries using $d->db->last_query(), or even better, enabling the CI profiler, and looking through all of the queries?

6) Also, just because error is empty, doesn't mean that something didn't go wrong. When saving relationships, for example, you may get a FALSE response, but no error message. This means that the attempt to save the relationship failed, usually either $d or $b (in your example) are not defined (ie: do not have an ID set), or that the relationship is improperly defined.

This is what I mean by not enough information. Saying that $a->save($b) doesn't work just tells me that the problem is on your end. Obviously that code snippet isn't the issue, or no-one could use DMZ. (BTW: here's a smiley, I'm not angry :-P)

[eluser]Matthew Lanham[/eluser]
@OverZealous

Can you tell me if there is a way to force insert rather than update, the reason i ask is that as soon as i specify an id it automatically assumes it's an update, however on this particular data i am inputing i want to preserve the id from another database.

[eluser]OverZealous[/eluser]
Nope. You cannot use DataMapper to do that.

You might be able to hand copy out the chunk of code that does the insert (see the save() method), and paste it into your own Extension. It shouldn't be too difficult.

Also, this is in the FAQ:
Why can I not save an item with a specific ID?

[eluser]tdktank59[/eluser]
@Overzealous

Just took a look again... Heres the modified code to remove any doubt of anything not working...
Code:
$d = new Dqip();
$d->where('title',$this->input->post('title'))->get();

// It was a brainstorm being promoted so lets relate the brainstorm to the new dqip
$b = new Brainstorm();
$b->where('id',$this->input->post('brainstorm_id'))->get();

if (!$b->save($d))
{
    echo 'DID: '.$d->id.'<br />BID: '.$b->id.'<br />';
    echo 'Error1: '.$d->error->string.'<br />Error2:'.$b->error->string;
}

It prints out
Quote:{#} is an actual number
DID: {#}
BID: {#}
Error1:
Error2:


This is still not saving. I turned the profiler on and all it is doing is grabbing the brainstorm and the dqip. However it is not saving them...
I also checked to make sure the join table is spelled right "join_brainstorms_dqips" which if im not mistaken the correct spelling and way of doing it...

Brainstorm Model:
Code:
class Brainstorm extends DataMapper
{
    var $table = 'brainstorms';

    var $has_many = array("dqip");
...

Dqip Model:
Code:
class Dqip extends DataMapper
{
    var $table = 'dqips';

    var $has_many = array( "problem", "brainstorm");
...

UPDATE:
I am now doing a work around with active record instead of using datamapper. It is inserting properly...

Code:
$this->db->set('brainstorm_id',$b->id)->set('dqip_id',$d->id)->set('created_on',time())->insert('join_brainstorms_dqips');

[eluser]OverZealous[/eluser]
@tdktank59
Do you have trouble saving any other relationships? Or just this one?

Crap, accidentally submitted

I recommend backing up the current libraries/datamapper.php file, and replacing it with the one attached. This will allow you to see what's happening with the save.

It may not show anything, in that case, DMZ doesn't see any object to save in the ->save() command, for some reason.

-- test file deleted --

[eluser]tdktank59[/eluser]
Haven't tried saving any other relations... Basically every other one is a many to one relation which exists on the parent table...

Ill see if I can get another relation working...

Heres what its printing out
Quote:Saving a dqip:
Related Properties:
$this->id: 1
$save->id: 130

However it is not inserting it into the db...

[eluser]OverZealous[/eluser]
Well, something is wrong in your setup, because "Related Properties" is coming back empty. You don't have the "Production Cache" enabled, do you? Please don't enable that unless you are ready to go to production.

[eluser]tdktank59[/eluser]
Woops...
Thought I had turned that off...

Heres the new results
Quote:Saving a brainstorm:
Related Properties: Array ( [class] => brainstorm [other_field] => dqip [join_self_as] => dqip [join_other_as] => brainstorm )
$this->id: 133
$save->id: 4
Table to Save to: join_brainstorms_dqips

And wada ya know! Turning off the cache now saves the relationship...
Im guessing its because the cache did not have the relation...

* I feel stupid now btw... *

It is working now!!!

[eluser]OverZealous[/eluser]
There's a reason for those great big red sections at the top of the help documents Smile

Production Cache:
Quote:Important: You must clear the cache for any model you make changes to, whether that is in the database or in the file. Failure to do so will most likely result in errors, and could possibly lead to data corruption.

So, for a general clarification, don't use the production cache, unless you have a need for it.

Note: I added this to the FAQs.

[eluser]tdktank59[/eluser]
I do have a need for it... But I thought I had turned it off and refreshed the cache when I updated the models...




Theme © iAndrew 2016 - Forum software by © MyBB