Welcome Guest, Not a member yet? Register   Sign In
IgnitedRecord 1.0 pre-release
#51

[eluser]flojon[/eluser]
Suddenly I got this error. I don't know what I changed...
Quote:Fatal error: Call to a member function find_all_by() on a non-object in /Users/flojon/Sites/anmalan.nu/system/application/models/IgnitedRecord/ignitedrecord.php on line 1414

but I think I found a fix for it. I think your test:
Code:
if(!in_array($data['model'],get_object_vars($CI)))
fails even though the model isn't loaded. So I replaced it with:
Code:
if(!isset($CI->$data['model']))
In all places, and now it works again.
#52

[eluser]Animas[/eluser]
I found another project "ActiveRecord Class Mod". Can you tell me the difference with this project? Which one will be easier and feature rich?
#53

[eluser]m4rw3r[/eluser]
Well, by asking me you are asking for a biased opinion Tongue

Things that differ (I may have missed a few features):
- IgnitedRecord is fully PHP 4 compatible (except the aggregation of behaviours, but does not really count)
- IgnitedRecord can use pure SQL
- IgnitedRecord has a lot of hooks, so it is easier to implement addons/plugins/behaviours (see the Act As Timestamped plugin above)
- IgnitedRecord has support of behaviours
- IgnitedRecord assumes default values, but is configurable

- ActiveRecord Class Mod enforces stricter naming conventions
- ActiveRecord Class Mod has it's own SQL string builder (IR is using CI's AR, for now)
- ActiveRecord Class Mod has JOINs built in (and easy to access, via functions, in IR you must write the SQL yourself)
#54

[eluser]flojon[/eluser]
I get the following error when I try to restore an IgnitedRecord object from the $_SESSION array:
Quote:The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "IgnitedRecord_record" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition

Any thoughts on what to look for?

At first I had forgot to load the model, but I get the same error even when I load the model. This is the code:
Code:
$this->load->model('registration');
$r = $_SESSION['registration'];
$r->value = $this->input->post('value');

Thanks!

EDIT: Solved: One must load the model before session_start! Silly me... ;-)
#55

[eluser]Hyra[/eluser]
Is there gonna be support for "order by" functionality?

Code:
$this->load->orm('Artworks', 'artworks');
$artwork = $this->artworks->find_by('ArtworkID', $artworkid);

$comments = $artwork->get_related('ArtworkComments');

works a charm, but the comments are ordered "randomly".

It would be nice to be able to add something like

Code:
$comments = $artwork->get_related('ArtworkComments')->order_by('CommentID', 'DESC');
#56

[eluser]m4rw3r[/eluser]
Oh, that is something I'll look into.
I'm currently redesigning the whole relationship part of IgnitedRecord (one third of the code, which is annoying, but I can see how it will improve IgnitedRecord), because of the bug with auto finding models.

So I hope I can implement it.

(and to all others out there having suggestions for the relation part of IgnitedRecord, go ahead and make suggestions while I'm redesigning it!)
#57

[eluser]flojon[/eluser]
I don't know if it's related to relatationships but I have a change I would like. I'm implementing validation as a behaviour and there needs to be some changes in the IgnitedRecord class for this to work. The hooks (or at least the save_pre_strip_data hook that I'm using) needs to be able to abort the current operation. So in my case if the hook return false, the save operation will abort. I've realized that this has implications on the rest of the code since save is called in few places and doesn't look at the return value. I made the following "hack" to make it work but maybe you could have this in mind if you're doing such a large rework anyway.
Code:
function hook($name,$data = array()){
                // Have we got a hook for this specific event?
                if (!isset($this->__hooks[$name])) {
                        // No, do nothing
-                       return;
+                       return true;
                }
                else{
                        // Yes, sort the list by priority
                        ksort($this->__hooks[$name]);
                }
+               $success = true;
                foreach($this->__hooks[$name] as $priority => $functions){
                        if(is_array($functions)){
                                foreach($functions as $func){
-                                       call_user_func_array($func,$data);
+                                       if (call_user_func_array($func,$data) === FALSE)
+                                               $success = FALSE;
                                }
                        }
                }
+               return $success;
        }

        function save(&$object, $force = false){
                if($this->__table == $object->__table){
-                       $this->hook('save_pre_strip_data',array(&$object));
+                       if ($this->hook('save_pre_strip_data',array(&$object)) === FALSE)
+                               return FALSE; // hooks failed
                        // remove some values that shall not belong in the database
                        $data =& $this->_strip_data($object);
                        $this->hook('save_post_strip_data',array(&$data));

Thank you for your superb work!

Regards,
Jonas
#58

[eluser]sophistry[/eluser]
EDIT: OOPS! um... sorry! scratch that comment about PHP5 everyone. i was looking in the wrong place in the PHP manual. those functions are PHP4 compatible.

since you asked for feedback :-) ...

the 012 trunk has two Magic functions that are PHP5 only ( namely, __sleep() and __wakeup() ). are you dropping support for PHP4 in the next release?

thanks! (stuck on 4 for now).
#59

[eluser]m4rw3r[/eluser]
@flojon
I realize how useful it is for a behaviour to be able to abort save (and delete, perhaps?), so I will apply your patch (thanks!).

@sophistry
Glad you found Classes and Objects (PHP 4) - The magic functions __sleep and __wakeup, they are sometimes a bit messy, those docs Smile
#60

[eluser]Hyra[/eluser]
Again, great work! I tried the package in my current site to see how it would work, and it does just that: work Smile

But for more complicated tasks it seems I will either have to extend the IgnitedRecord model, which would make upgrading it in case of a new version not so pleasent or I will have to find a way to extend the derived classes for added functionality.

But maybe I'm just not seeing something.

How would one go about the following.

Tables:
Users
Has the simple data from the regged users such as a name and location.
Posts
Contains the posts made by the users, foreign keyed with a UserID in the table.
Comments
Contains the comments made on the posts, foreign keyed with a PostID and UserID in the table.

The User class would look something like

Code:
class Users extends IgnitedRecord {
    
    var $__table = "Users";
    var $__has_many = array('table' => 'Posts', 'col' => 'UserID');
    var $__id_col = "UserID";
    
    function __construct() {
        parent::IgnitedRecord();
    }

};

The Post class

Code:
class Posts extends IgnitedRecord {
    
    var $__table = "Posts";
    var $__id_col = "PostID";
    
    var $__belongs_to = array('table' => 'Users', 'col' => 'UserID');

    var $__has_many = array('table' => 'Comments', 'col' => 'PostID');

    function __construct() {
        parent::IgnitedRecord();
    }

};

and finally, the comments

Code:
class Comments extends IgnitedRecord {
    
    var $__table = "Comments";
    var $__belongs_to = array('table' => 'Posts', 'col' => 'PostID');
    var $__id_col = "CommentID";
    
    function __construct() {
        parent::IgnitedRecord();
    }

};


How would you show a list of a certain post with all its comments where the comments show the User names as well?

Code:
// Retrieve the data of the post
// This will leave us with just the UserID, not the name
$post = $this->posts->find_by('PostID', $postid);

// Retrieve the comments on the post
// This works great, giving all related comments, but again, without the users name
$comments = $post->get_related('Comments');

Would one have to loop through all the comments in a foreach and retrieve the username by doing?
Code:
$comments[i]->UserName = $this->users->find($comments[i]->UserID);

As that seems server intensive, and as the fields grow (location, etc.) it would become tedious. Especially if you use it on more than one page (unless you store it in a subroutine somewhere, making the code less "watchable"

Anyway, like i said, maybe I just missed a line in your manual. Which is great btw.




Theme © iAndrew 2016 - Forum software by © MyBB