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

[eluser]naren_nag[/eluser]
SOLVED: I has called my controller Article as well. That was the problem. Basically changing the controller's name was all it took.


Ok, very strange error.

First, the error messages:

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Article::$form_validation

Filename: libraries/datamapper.php

Line Number: 3626

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Article::$db

Filename: libraries/datamapper.php

Line Number: 3629

Here's where it starts to get strange, in datamapper.php

Code:
3626       $this->form_validation = $CI->form_validation;
3629       $this->db = $CI->db;

I *ONLY* get this error under this particular circumstance

Code:
// Create the article object
$articleObject = new Article();

// Assign the POST values to it that I've got from the form

$articleObject->author = $author;
$articleObject->title = $title;
$articleObject->body = $body;
$articleObject->extract = $extract;

// Create the Category object before the save
// THIS is what is giving the error
// If I comment out the two lines below, I can't save, but I can var_dump
// and get no errors.

$categoryObject = new Category();
$categoryObject->get_by_id($category_id);

// Save

$articleObject->save( array($category, $userObject) );

The models themselves are as simple as they can get

Code:
class Category extends Datamapper {

  var $has_many = array("article");

  ...

}

class Article extends Datamapper {
  
  var $has_one = array("category", "user");
  
  ...
}

class User extends Datamapper {

  var $has_many = array("article");

  ...
}

Like I've written in the comments above, the moment I create a category object I get this error. If I comment it out, no problems.

Any clues?

cheers,

Naren

[eluser]OverZealous[/eluser]
I don't think the error is not being caused by the two lines. When you comment them out, the $save below them just doesn't attempt to save the Category. The error message explicitly mentions Article, so the error is most likely related to Article.

Do you have a controller that is also named Article?? You cannot have controllers with the same name as your Models (otherwise one class will override the other).

[eluser]naren_nag[/eluser]
[quote author="OverZealous.com" date="1244420384"]I don't think the error is not being caused by the two lines. When you comment them out, the $save below them just doesn't attempt to save the Category. The error message explicitly mentions Article, so the error is most likely related to Article.

Do you have a controller that is also named Article?? You cannot have controllers with the same name as your Models (otherwise one class will override the other).[/quote]

You're right on the ball Phil, just updated my post to say I had called the controller the same name as the class :p

thanks,

[eluser]tdktank59[/eluser]
All right this might be covered somewhere but I can't seem to find it...

I know you added the functionality to have more field in join tables.

So I have this table

join_roles_users
- id
- role_id
- user_id
- start_time
- end_time
- created_on
- updated_on

I need to be able to set the last 4 values... (start_time to updated_on)

[eluser]OverZealous[/eluser]
@tdtank59
You'll want to look at:

set_join_field($related_model, $field, $value): in this case it would look like:
Code:
$user->set_join_field('role', 'start_time', $start_time);
// OR
$role->set_join_field('user', 'start_time', $start_time);

(where | where_in | like | ...)_join_field($related_model, $field, $value): use this for querying on those fields:
Code:
$user->where_join_field('role', 'start_time >', $start_time);

include_join_fields($related_model): Use to be able to read back the join fields:
Code:
$user->include_join_fields('role')->get();
echo $user->start_time; // I think :)

They are all described on the first post, under Update, View, and Query Extra Columns on Join Tables

[eluser]tdktank59[/eluser]
Thanks, Ill let you know if I have any issues.

[eluser]warrennz[/eluser]
Heya guys

Can someone please give me an example on how to setup multiple relationships on a single object. Ive tried many times, following the examples essentially by the letter, with no luck. Maybe it's just not meant to be.

I have a user and account table.

It's a 1:M relationship between users and accounts respectively.

I need to have a creator, installer and a canceler as well as the original user, which I guess is the owner.

One thing that always confused me about the concept is that each new relationship required 2 new fields.
With a single relationship the join table just has account_id and user_id. I figured the a new relationship on the same object would just add a creator_id, but DM always asked for a 2nd field for that relationship which was intended to be the account_id again? Does that mean there's going to be 2 columns exactly the same? Is that the way its intended to work?

I dunno, I'm getting to old for this Tongue

Appreciate it Smile

THanks

[eluser]OverZealous[/eluser]
@warrennz
It looks like they are all $has_one relationships, correct?

If this is the case, then you don't need a separate table at all. Add these columns to the accounts table:
Code:
* creator_id
* installer_id
* canceler_id
* owner_id

Then, set up your models like this:
Code:
class Account extends DataMapper {
    $has_one = array(
        'creator' => array('class' => 'user', 'other_field' => 'createdaccount'),
        'installer' => array('class' => 'user', 'other_field' => 'installedaccount'),
        'canceler' => array('class' => 'user', 'other_field' => 'canceledaccount'),
        'owner' => array('class' => 'user', 'other_field' => 'ownedaccount')
    );
}

class User extends DataMapper {
    $has_many = array(
        'createdaccount' => array('class' => 'account', 'other_field' => 'creator'),
        'installedaccount' => array('class' => 'account', 'other_field' => 'installer'),
        'canceledaccount' => array('class' => 'account', 'other_field' => 'canceler'),
        'ownedaccount' => array('class' => 'account', 'other_field' => 'owner')
    );
}

Notice how each reference is mirrored, so that other_field becomes the relationship key on the opposite object.

Alternatively, you can make any one of those (say, owner) a standard relationship. Ex: change the column from owner_id to user_id, and replace the whole owner with just user and ownedaccount with just account.

Finally, if you want to continue to use a dedicated join table, or these are not $has_one relationships, you need to set up a single accounts_users table with these columns (or you can mix-and-match):
Code:
* id
* owner_id
* ownedaccount_id
* creator_id
* createdaccount_id
* etc.

All columns are integers and must allow NULLs.

In other words, DMZ will always look for the same join table when relating two different objects, but use the column names generated from the related_field name.

Accessing those relationships are like normal, e.g. $account->canceler->get().

[eluser]warrennz[/eluser]
@OverZealous.com

Thanks a bunch. I'll give this a crack shortly.


Thanks

[eluser]OverZealous[/eluser]
Notification to my users:

I have finally updated the dang documentation. I think I just spent about 10 hours going through it line-by-line.

Anyway, please see the first post, or just visit:
http://www.overzealous.com/dmz/ (Check out that logo!)

Highlights:
* In-Table Foreign Keys. See how you can reduce your table count!
* Advanced Relationships, where I attempt to explain the new relationship techniques.
* Advanced Get. Now with more information about join fields, and including other columns!
* Working with Join Fields; Aren't they useful?
* And more!




Theme © iAndrew 2016 - Forum software by © MyBB