Part of the EllisLab Network
   
57 of 57
57
IgnitedRecord 1.0 pre-release
Posted: 08 August 2009 05:54 AM   [ Ignore ]   [ # 561 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  740
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 05: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 04:49 PM   [ Ignore ]   [ # 563 ]  
Summer Student
Total Posts:  5
Joined  08-15-2008

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

Profile
 
 
Posted: 15 February 2010 11:23 PM   [ Ignore ]   [ # 564 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  168
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 12:37 AM   [ Ignore ]   [ # 565 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  168
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 01:51 PM   [ Ignore ]   [ # 566 ]  
Summer Student
Total Posts:  22
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
 
 
   
57 of 57
57
 
‹‹ 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 10:15 AM
Total Registered Members: 119534 Total Logged-in Users: 49
Total Topics: 125766 Total Anonymous Users: 5
Total Replies: 661786 Total Guests: 491
Total Posts: 787552    
Members ( View Memberlist )