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

[eluser]m4rw3r[/eluser]
@Jonas G:

You call IgnitedRecord::get(), which only returns a single record.
Then you loop the properties of that record and __instance is the first key up.
So the code in the foreach loop try to call $this->outcome->related('bettingoffer')...

Solution:
Remove the foreach($outcomes) or replace get() with find_all().

[eluser]m4rw3r[/eluser]
Oh, and about methods in the model:

Make them as usual, ie. put in a library if it is a too large abstraction of the data or if there are may sources of the data (eg. access library, some kind of page handling lib with multiple parts and templates etc.).
Just keep in mind that $this is the query building object, and don't overwrite any of the IgnitedQuery or IgnitedRecord methods (api doc generated with PHPdoc can help).

[eluser]hudar[/eluser]
@m4rw3r

Ok, great, thanks. Keep up a good work.

We are waiting for official release of IgnitedRecord 1.0 Smile

[eluser]Jonas G[/eluser]
Thanks for the replies

Quote:Just keep in mind that $this is the query building object, and don’t overwrite any of the IgnitedQuery or IgnitedRecord methods (api doc generated with PHPdoc can help).

So how do I access eg. $this->config->item() from an IR model?

[eluser]m4rw3r[/eluser]
Use get_instance() to get the controller.
IR only has $this->db populated.

[eluser]Jonas G[/eluser]
Hi again

I have a comments table that holds comments for both blog and news. In my blog model, how do I set up the relationship correctly? The comments table looks like this:

area | parent_id
'blog' | 15
'news' | 2

This could easily collide if I don't select by 'area'.

/Jonas

[eluser]Jonas G[/eluser]
Also: Is there a good way to count the number of comments a blog entry has without running a query for every entry? Before I switched to IR I would add
Code:
if ($get_comment_count) {
            $comment_table = $this->config->item('comments_table');
            $this->db->select('COUNT('.$comment_table.'.id) as comment_count', false);
            $this->db->join($comment_table, $comment_table.'.parent_id = '.$table.'.id', 'left');
        }
To my model function, but can't seem to get around this using IR.

On the same note, is there any way to 'add' and entry to the object array. eg. I run
Code:
$data['blogs'] = $this->blog->limit(25)->find_all();
foreach ($data['blogs'] as $b) {
$data['comment_count'][$b->id] = $b->related('comments')->count();
}
But I would much rather be able to 'add' 'comment_count' to each $data['blogs'].

Anyways - I hope you know what I mean - it's getting late.

/Jonas

[eluser]m4rw3r[/eluser]
@Jonas G, post 1:

What do you mean with collide? Is it an adjacency list?

@post 2:

You can add extra columns by manipulating the query object, this should probably do it:
Code:
if($get_comment_count)
{
    // adds an extra column to the main objects (ie. blog objects in your case)
    $this->select('COUNT(comments.id) AS `comment_count`');

    // the second parameter controls which columns to join into the main objects
    // false (default) creates new objects for the joined data, true makes it skip all columns and objects
    $this->join_related('comments', true);
}

[eluser]Jonas G[/eluser]
Hi m4rw3r

Thanks for the reply

What I mean by collide is that the comments table holds comments for both blog and news. Say I want to count the comments for a blog entry with the id of 4 and I did a
Code:
$this->select('COUNT(comments.id) AS `comment_count`');
$this->join_related('comments', true);

That would count both comments for the 'news entry' of id = 4 AND the 'blog entry' of id = 4.

What I need is something like:
Code:
$this->select('COUNT(comments.id) AS `comment_count WHERE area = 'blog'`');
$this->join_related('comments', true);

Would that work? Is there a better way of doing that? It would be cool if this could be configured from the model.

Thanks for a great library - I have just started to rewrite my site to use IR. Better documentation and a list of 3rd party behaviours would be a great addition.

Jonas

[eluser]Jonas G[/eluser]
It's me again Smile

I have this controller:
Code:
function delete($id)
    {
        $record = $this->blog->find($id);
        $record->delete_all();
        
        redirect('admin/blog');
    }

And get this error:
Code:
IgnitedRecord: IR_record: Method delete_all() is not found.

This, however, works fine:
Code:
function delete($id)
    {
        $record = $this->blog->find($id);
        $record->delete();
        
        redirect('admin/blog');
    }

What am I doing wrong?

Sorry for posting so much - i'm in a real hurry with a project and IR could really save my skin.




Theme © iAndrew 2016 - Forum software by © MyBB