Part of the EllisLab Network
   
2 of 57
2
IgnitedRecord 1.0 pre-release
Posted: 02 May 2008 11:07 AM   [ Ignore ]   [ # 11 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  740
Joined  08-03-2006

Whoops, I forgot the double underscore before the instance property (had started to move some methods from MPTtree ORM to IgnitedRecord, so I guess I forgot them (MPTtree uses only instance, without underscores)).

Updated the errata.

Thanks!

 Signature 

RapidDataMapper: My new ORM, is now released!

IgnitedRecord: Old ORM

MPTtree: A model to handle trees in a database.

YAYParser - Yet Another YAML Parser

Profile
 
 
Posted: 02 May 2008 11:35 AM   [ Ignore ]   [ # 12 ]  
Summer Student
Total Posts:  10
Joined  02-13-2007

Thanks for the fix, m4rw3r; for some reason the following is not working though.

$post->add_relationship($tag);

I would expect it to create a new record in the posts_tags table, but it doesn’t.


Edit: sorry, my fault, all’s working wonderfully now :D

Profile
 
 
Posted: 02 May 2008 11:56 AM   [ Ignore ]   [ # 13 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  740
Joined  08-03-2006

Have you defined a has and belongs to many relationship between the two models (it is needed at least for the object where you are calling add_relationship())?
Because it is working fine for me…

// here is the relationship needed, because you establish a relation from a child record of this class
class post extends IgnitedRecord{
    
var $__has_and_belongs_to_many = 'tags';
    function
post(){
        parent
::IgnitedRecord();
    
}
}
// not needed here, but if you want to call $tag_rec->add_relationship($post_rec); you have to define the relation in here
class tag extends IgnitedRecord{
    
var $__has_and_belongs_to_many = 'posts';
    function
tag(){
        parent
::IgnitedRecord();
    
}
}

Or have you forgotten the double underscores prefixing the properties?

EDIT: Didn’t see that you cleared that up

 Signature 

RapidDataMapper: My new ORM, is now released!

IgnitedRecord: Old ORM

MPTtree: A model to handle trees in a database.

YAYParser - Yet Another YAML Parser

Profile
 
 
Posted: 02 May 2008 12:07 PM   [ Ignore ]   [ # 14 ]  
Summer Student
Total Posts:  10
Joined  02-13-2007

Okay I’ve got another problem for you to solve raspberry

I’m trying to delete a record from the database, and see if also the corresponding relationships are deleted too, so I write this:

$post = $this->post->find(2);
$post->delete();

I get this error:

Message: Invalid argument supplied for foreach()
Filename: models/ignitedrecord.php
Line Number: 933

Profile
 
 
Posted: 02 May 2008 12:17 PM   [ Ignore ]   [ # 15 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  740
Joined  08-03-2006

Could you post your derived class?
Because everything works fine for me (the delete() method loops all relations and deletes them, so it is something with the relation properties).

 Signature 

RapidDataMapper: My new ORM, is now released!

IgnitedRecord: Old ORM

MPTtree: A model to handle trees in a database.

YAYParser - Yet Another YAML Parser

Profile
 
 
Posted: 02 May 2008 12:18 PM   [ Ignore ]   [ # 16 ]  
Summer Student
Total Posts:  10
Joined  02-13-2007
class Post extends IgnitedRecord {
    
    
var $__has_and_belongs_to_many = 'tags';

    function
Post()
    
{

        parent
::IgnitedRecord();

    
}

}

Nothing more than this…

Profile
 
 
Posted: 02 May 2008 12:23 PM   [ Ignore ]   [ # 17 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  740
Joined  08-03-2006

Ok, this problem arises when a record which hasn’t loaded any relations is being deleted.
The __relation_properties in the IgnitedRecord_record class must be set to array() in the declaration.

Updating the errata.

Anyway, please give me more feedback (not only error reports, but error reports are fine I guess (then I have something to do, and I know that I’ve not wasted my time raspberry))!

 Signature 

RapidDataMapper: My new ORM, is now released!

IgnitedRecord: Old ORM

MPTtree: A model to handle trees in a database.

YAYParser - Yet Another YAML Parser

Profile
 
 
Posted: 02 May 2008 05:03 PM   [ Ignore ]   [ # 18 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  431
Joined  10-11-2007

Just FYI, I’ve had to move on from attempting to use this at the moment, so I won’t be posting any additional comments at least for the near future. It shows promise, so I’ll probably take a look again in a few weeks. Thanks for the efforts thusfar.

 Signature 

BarrettNewton.com

Profile
 
 
Posted: 03 May 2008 01:03 PM   [ Ignore ]   [ # 19 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  740
Joined  08-03-2006

IgnitedRecord have now been updated to 0.1.0 RC 4

I have now made some changes on how the more “advanced” relations (not using all defaults) are defined:
previous:

var $has_one = array('tablename' => array('name' => 'relationname', 'col' => 'foreign_key'),
                     
'tablename2' => array('name' => 'rel2')
                    );

the new way:

var $has_one = array(array('table' => 'tablename', 'name' => 'relationname', 'col' => 'foreign_key'),
                     array(
'table' => 'tablename', 'name' => 'another_to_same')
                    );

Personally I think the new version is more descriptive, and it adds a new feature: Now you can relate to the same table with different relationnames using the same relation type.
Example:

class thread extends IgnitedRecord{
    
var $has_many = array(array('table' => 'posts', 'col' => 'thread_id'),
                          array(
'table' => 'posts', 'col' => 'thread_id_comment', 'name' => 'comments')
                         );
}

In the model above, we have both comments and posts stored in the same table. If a post is only a comment, it has only the thread_id_comment set, if it is a post it has thread_id set, and if it is both it has both set.

Some bugs have been corrected and loading of relations now logs a warning if no relation with that name was found.
I’ve also added calls to show_error() in the __call() methods if no method is found.

I’m currently playing around with JOINs and aliases, and if somebody wants to help I’d be grateful. It seems like IgnitedRecord would loose a lot of flexibility when fetching objects if I implement the JOINs like my current experimentations suggests, so I will probably make join variants of most of the existing methods for fetching data.
If anyone have a suggestion on how to implement JOINs, please share.

Thanks for your feedback!

 Signature 

RapidDataMapper: My new ORM, is now released!

IgnitedRecord: Old ORM

MPTtree: A model to handle trees in a database.

YAYParser - Yet Another YAML Parser

Profile
 
 
Posted: 08 May 2008 08:28 PM   [ Ignore ]   [ # 20 ]  
Grad Student
Avatar
Rank
Total Posts:  100
Joined  12-27-2007

@m4rw3r:
I have a questions.
my table was not designed having field like user_id, order_id, etc ... i just simply write like userid, orderid, etc ...

can your orm support this without changing your code ?

thanks

 Signature 

[color=blue]——
wysmedia.com
Using:Code Igniter 1.6.2

Programming: 90% make data validation, 9% UI, 1% data entry
Profile
 
 
   
2 of 57
2
 
‹‹ It worked      Extension to the Table Class ››
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 819, on March 11, 2010 11:15 AM
Total Registered Members: 120322 Total Logged-in Users: 52
Total Topics: 126442 Total Anonymous Users: 3
Total Replies: 664918 Total Guests: 496
Total Posts: 791360    
Members ( View Memberlist )