Part of the EllisLab Network
   
57 of 57
57
IgnitedRecord 1.0 pre-release
Posted: 08 August 2009 07:54 AM   [ Ignore ]   [ # 561 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  727
Joined  08-03-2006

IgnitedRecord is not a dead project, but it is on a hiatus for now. I don’t know when I will continue on it (although I don’t see myself doing major work on it, more like I will fix minor things).

I started to rewrite my new ORM from scratch yesterday, primarily because the code builder I made for it did not really work in a manner which was flexible enough. The major reason for that is the way the configuration objects were structured.

The new configuration is handled by objects which the user have a direct influence over, the descriptors.
A descriptor describes a class and also provides the occasional code piece for the code builder, which makes for an easy and powerful way of extending the code.

And yes, I’m trying to keep the same sane defaults I made for IgnitedRecord in my new ORM. The flow is quite similar and the loading of related records must be explicitly called, just as in IgnitedRecord.

Example:

class User
{
    
public $id;
    public 
$name;
    public 
$posts = array();
}
class UserDescriptor extends Db_Descriptor
{
    
function __construct()
    
{
        $this
->add($this->newPrimaryKey('id'));
        
$this->add($this->newColumn('name'));
        
        
// Automatically figures that it is a has many relationship:
        
$this->add($this->newRelation('posts'));
    
}
}

class Post
{
    
public $id;
    public 
$user_id;
    public 
$title;
}
class PostDescriptor extends Db_Descriptor
{
    
function __construct()
    
{
        $this
->add($this->newPrimaryKey('id'));
        
$this->add($this->newColumn('user_id'));
        
$this->add($this->newColumn('title'));
    
}
}

$u 
Db::find('user')
    ->
where('user.id'2)
    ->
related('posts')
    ->
like('user-posts.title''foobar')
    ->
getOne();

echo 
$u->name;

foreach(
$u->posts as $p)
{
    
echo $p->title;

If you want to have a look at the code, look here: http://github.com/m4rw3r/RapidDataMapper/tree/master

If you’d like to have a special feature, just send me a message (or add a ticket).
I have a lot of features I’ve made in the earlier version, before the rewrite, which means that those will be quite quick to implement.

 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: 24 September 2009 07:17 AM   [ Ignore ]   [ # 562 ]  
Summer Student
Total Posts:  5
Joined  08-15-2008

Hi,
I have a related_by problem.

Here is my example:
Every Posts is written by an user.

So, the

$post->user_id 
is pointing to
$user->id 

.

I want to fetch all posts and echo the $post->title and the $user->name (or is it $post->user->name?)

I need an example for my models (user and post) and the controller.

How can I fetch all posts and the user names?

It should be like this

foreach($posts as post){
  
echo $post->title.'-----'.$post->user->name;

Every help is welcome!
Thank you very much.

Christian

Profile
 
 
Posted: 02 October 2009 06:49 PM   [ Ignore ]   [ # 563 ]  
Summer Student
Total Posts:  5
Joined  08-15-2008

ok, my problem is solved.
I LOVE THIS LIB!

Profile
 
 
Posted: 16 February 2010 01:23 AM   [ Ignore ]   [ # 564 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  190
Joined  12-04-2008

Hello Martin (and whoever else reads this),

A situation has come up where i need to modify a table and add a column just before an update on an ignitedrecord model. All good however just as I had suspected when the model is first loaded, ignitedrecord must inspect the database and identify the columns in the table. The problem is that if I modify the columns on the fly then when I add data to the new column, ignitedrecord ignores it because it doesn’t know about the column.

Eg..

// Get field name based on posted name
$field strtolower(url_title($this->input->post('name')));
// Make a field matching the name for this table
if(!$this->db->field_exists($field'people')) {
    $this
->load->dbforge();
    
$this->dbforge->add_column('people', array($field=>array('type'=>'VARCHAR','constraint'=>'250')));
}                 
// All good, save to the database
$data['person']->name $this->input->post('name');
$data['person']->$field 'Yes this field works';
$data['person']->save(); 

This is just example code to test my proof of concept.

Is there some way to tell ignitedrecord to reload the model? Or is there some way we can unload the model and then reload it? Or is there some other way I can let ignitedrecord know about the new column name for that model?

Thanks for your help… Sorry it is a bit of a crap question.

Profile
 
 
Posted: 16 February 2010 02:37 AM   [ Ignore ]   [ # 565 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  190
Joined  12-04-2008

I may have solved it with the following code. Note the two extra lines adding the table columns to the model object.

// Get field name based on posted name
$field strtolower(url_title($this->input->post('name')));
// Make a field matching the name for this table
if(!$this->db->field_exists($field'people')) {
    $this
->load->dbforge();
    
$this->dbforge->add_column('people', array($field=>array('type'=>'VARCHAR','constraint'=>'250')));
    
// Manually add the table columns so ignitedrecord saves em
    
$this->person->columns $this->db->list_fields('people');
    
$this->person->columns[] $field;
}                 
// All good, save to the database
$data['person']->name $this->input->post('name');
$data['person']->$field 'Yes this field works';
$data['person']->save(); 

If you can see a better way please let me know. Thanks!

Profile
 
 
Posted: 21 February 2010 03:51 PM   [ Ignore ]   [ # 566 ]  
Summer Student
Total Posts:  25
Joined  01-02-2010

Hello,

I have a litte problem.
the function delete() don’t work.

 Signature 

The Site,I developed/ing with CI

Profile
 
 
Posted: 01 November 2010 12:07 PM   [ Ignore ]   [ # 567 ]  
Summer Student
Total Posts:  25
Joined  01-02-2010

Hello

I want to pick up an bug.

when i want this

table 1 anime
Table join
table image

$image=$this->anime->related(R_IMAGES_ANIMES)->where(‘image_id’, $id)->get();

if i do $image->name, error call no objet.

but when i do a var_dump$image) i

public ‘__data’ =>      array       ‘id’ => string ‘72’ (length=2)        ‘name’ => string ‘ce25e09cd1f725ad71c8b509390a9519.png’ (length=36)        ‘height’ => string ‘180’ (length=3)        ‘width’ => string ‘545’ (length=3)        ‘type’ => string ‘anime’ (length=5)        ‘theme_id’ => null       ‘created_at’ => string ‘2010-10-31 17:06:49’ (length=19)        ‘created_by’ => string ‘0’ (length=1)        ‘updated_at’ => string ‘2010-10-31 17:06:49’ (length=19)        ‘updated_by’ => string ‘0’ (length=1)

SO IR find bit i can’t use!!

If somebody can help me.

 Signature 

The Site,I developed/ing with CI

Profile
 
 
   
57 of 57
57
 
‹‹ It worked      Extension to the Table Class ››