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

[eluser]m4rw3r[/eluser]
What you can do is to use the dbobj2orm() method of IR_base (which means that all models extending IgnitedRecord has it) to convert an object of db_result into IR_records (or whatever class is specified).

To easily make a query to the database, create an instance of IgnitedQuery, it is IR's replacement of ActiveRecord and is made as a stand alone lib too (I've just made IR_base extend IgnitedQuery to get the SQL building methods).

Example usage:
Code:
// in the model:
function &foo;()
{
    // This is also the usage if you want to use it as a stand alone lib, which works perfectly fine:
    $query = new IgnitedQuery();
    $query->select('foo, bar'); // Just treat it as if you use CI's $this->db
                                // (but there are differences, at least with 1.7 of CI)
    $query->from($this->table); // We make it dynamic, so we can reuse the code
    
    $result = $query->get();    // Just as a normal CI query

    return $this->dbobj2ORM($result); // now we let dbobj2ORM do its magic :)
    // (pass true as the second parameter if you only want a single IR_record returned,
    // otherwise the records are encapsulated in an array)
}
I do hope the sum functions work as they should, I've primarily tested all where and like statements.

[eluser]dcunited08[/eluser]
Code:
$this->select(array('ThicknessNameOut', 'WidthNameOut', 'LengthNameIn'));
$this->select_sum('BoardFeetIn');
$this->select_sum('SumPieceCount');
$this->from($this->table);
$this->where('BoardFeetIn > ', 1);
return $this->find_all();

This worked in 0.2.0 but fails, as you described, in 1.0 because there is a
Code:
$this->select($this->table.'*');
that was added to the running of the find_all. It is useful to have that select all in there but it would be nice to be able to go around it.

[eluser]m4rw3r[/eluser]
The reason I have this code:
Code:
$this->select($this->table.'*');
Is because I don't want to have the JOINs messing with the most important part of the query, the "main" object(s) to fetch (if a join is specified, IR won't have any selectors for the "main" table).

Actually, if you want to call the IgnitedQuery::get() from the IgnitedRecord class, you should be able to call it as a static method:
Code:
function foo()
{
    $this->select('something');

    $q =& IgnitedQuery::get($this->table);

    return $this->dbobj2ORM($q);
}

[eluser]dcunited08[/eluser]
Excellent, thank you very much!

[eluser]voland[/eluser]
Hi. find_by_sql and find_all_by_sql doesnt work.

Message: Undefined property: User::$db

Filename: ignitedrecord/ignitedrecord.php

Line Number: 869

I think $this->db - doesnt exists).

[eluser]m4rw3r[/eluser]
Thanks!

Corrected it (the db property isn't needed, but I overlooked those methods when I removed $this->db).

[eluser]cayasso[/eluser]
I am trying to use CI Template Parser library(only accepts arrays) and IgnitedRecord library to pass the data using for example; But I need for this to work I would need to be able get the result from IgnitedRecord as an array and not an object, I am unable to figure out a good way to do this can any one help me out.

Model
Code:
class Contents extends IgnitedRecord{

}


Controller
Code:
class Content extends Controller{

function Content()
{
   parent::Controller();

   $this->load->orm('Content', 'content_mod');

   $this->load->library('parser');
}

function index()
{
   $data['content'] = $this->content_mod->find_all(); // This will return an Object Array and not Array
  
   $this->parser->parse('content_page', $data);
}

}

View

Code:
{content}
{title}
{entry}
{/content}

Is there a way i can go around this, if there is can you help me out with an example I will really appreciate it.

This is the error I get

Code:
A PHP Error was encountered

Severity: 4096

Message: Object of class Content could not be converted to string

Filename: libraries/Parser.php

Line Number: 104

Thank you!!

[eluser]sophistry[/eluser]
quick, but not tested...

does this help?
Code:
$data['content'] = (array)$this->content_mod->find_all();

[eluser]cayasso[/eluser]
Thanks sophistry but I got the same error!!!

[eluser]m4rw3r[/eluser]
The problem there is that the type-casting isn't recursive, and you'll end up with an array of objects (which it already was).
You need to make it recursive (and also to ignore properties like __instance).

I'm currently at school, so I'll post something when I get home.




Theme © iAndrew 2016 - Forum software by © MyBB