CodeIgniter Forums
DataMapper 1.6.0 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: DataMapper 1.6.0 (/showthread.php?tid=11358)



DataMapper 1.6.0 - El Forum - 01-29-2009

[eluser]Iverson[/eluser]
Quote:
Code:
unset($this->{$object->model});
with this one:
Code:
$this->{$object->model}->clear();

This should fix the problem, while still clearing out the related object.

UPDATE Question:
What version of PHP are you running? I tested it on mine, and PHP 5.2.6 had no problem calling the __get method after an unset.

UPDATE 2
One more: you actually have a mistake in your example code! You are calling sch->school, but you mean sch->student. That's your error.

I actually don't have that line in my datamapper file (1.6.0). And this isn't my actual situation. I just quoted it instead of saying the same thing over. My code is actually:
Code:
$cl = new Client();
$cl->get_by_id(1);
$cl->payment->get(); // Throws the error

And I'm running 5.2.8. Maybe that's a problem?


DataMapper 1.6.0 - El Forum - 01-29-2009

[eluser]OverZealous[/eluser]
Hmm, I must have modified MY version of DM already! Ha. OK, the correct line is to replace
Code:
// line # 2416
$this->{$object->model} = NULL;
with
Code:
unset($this->{$object->model});
Which will fix your problem.

I apologize, my DM has a handful of bugfixes that I'm pretty sure I sent to Stensi, but have long since forgotten about...

Then your problem should be gone.


DataMapper 1.6.0 - El Forum - 01-29-2009

[eluser]Iverson[/eluser]
Thanks for the help, but that didn't work either. I think it's because #2416 is in a delete relationship function. All I'm trying to do is get the related table.

Code:
// Client Model
class Client extends DataMapper {

    var $has_many = array('payment' => 'payments');
    var $unix_timestamp = TRUE;
    /**
     * Constructor
     *
     * Initialize DataMapper.
     */
    function Client()
    {
        parent::DataMapper();
    }


// Payment Model
class Payment extends DataMapper {

    var $has_one = array('client' => 'clients');
    var $unix_timestamp = TRUE;

    /**
     * Constructor
     *
     * Initialize DataMapper.
     */
    function Payment()
    {
        parent::DataMapper();
    }

// Controller
$cl = new Client();
$cl->get_by_id(1);
$cl->payment->get();



DataMapper 1.6.0 - El Forum - 01-29-2009

[eluser]OverZealous[/eluser]
Hmm, you need to be more specific when you post questions. The problem you referenced before was specifically related to deleting a related item, and is completely unrelated to the code you are showing.

In your quoted text, you are using the old method. DataMapper 1.6.0 (actually, since 1.4.0) doesn't use the associative has_one and has_many arrays. You just need to list the model names of the related objects.

Please read the DM change log. $unix_timestamp can also be specified within the DataMapper config file, and is not needed on the individual models unless you want different types of timestamps per model.


DataMapper 1.6.0 - El Forum - 01-29-2009

[eluser]tdktank59[/eluser]
Is there a way to get thing out of the relation table?

For example: I need to get start_date and end_date from the roles_users table

Quote:users
id
username
email
password
etc...

join_roles_users
id
role_id
user_id
created_on
updated_on
start_date
end_date


roles
id
name
description
created_on

UPDATE:
For the moment im just using custom queries attached to the page and method models. If there is a way to do it with Datamapper sweet otherwise this is a work around for it at the moment...


DataMapper 1.6.0 - El Forum - 01-30-2009

[eluser]macigniter[/eluser]
i just found out about this beautifully documented class and am just now experimenting with it. i have one question and please excuse me if it is stupid:

i ususally use prefixes for a logical group of tables (e.g. user management = user_****, tracking = track_**** etc.)

so i have a "faqs" table as well as a "track_faqs" table which holds all the stats. technically i would join the tables like this:

faqs
id
question
answer
...

track_faqs
id
hash
created

join_faqs_track_faqs
id
faq_id
track_faq_id

is it possible to use an underscore in a table name or is it forbidden?


DataMapper 1.6.0 - El Forum - 01-30-2009

[eluser]Murodese[/eluser]
Not a problem as far as I've encountered.


DataMapper 1.6.0 - El Forum - 01-30-2009

[eluser]macigniter[/eluser]
another question...

i have a "files" table that stores information on uploaded files. this table should have relations to
1. the user id of the user that uploaded the file (1:1)
2. a list of users that are allowed to view the file (m:n)

how would i do this without having to use the same join table name twice?

files
id
label
descr
...
created
updated

join_files_users (to store the user id of the creator of a file)
id
file_id
user_id

join_files_users (to store the users that are allowed to download a file)
id
file_id
user_id

i don't know how to solve this since i would have to use the same table name for the join tables, right?


DataMapper 1.6.0 - El Forum - 01-30-2009

[eluser]Murodese[/eluser]
Code:
class Uploader extends DataMapper
{
  var $table = 'users';

  var $has_one = array('file');
  
  // ...
}

class User extends DataMapper
{
  var $table = 'users';

  var $has_many = array('file');

  // ...
}

class File extends DataMapper
{
  var $table = 'files';

  var $has_many = array('user');
  var $has_one = array('uploader');

  // ...
}

And join tables would become files_users and files_uploaders.


DataMapper 1.6.0 - El Forum - 01-30-2009

[eluser]macigniter[/eluser]
Thanks!! I really appreciate your quick help