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

[eluser]m4rw3r[/eluser]
But you use the related() method in a foreach, which will make n + 1 queries to the DB.

So in your case (and any matching case) you can use join_related('status') to only make one query total
(it is more CPU intensive (because of splitting it into different objects), but PHP doesn't have to wait for database queries to finish).

Code:
// controller
$data['applications'] = $this->application->join_related('status')->find_all();

// view
<td>&lt;?= $a->status->name; ?&gt;</td>

[eluser]sofbas[/eluser]
That is better, you are absolutely right, in most circumstances I/O transactions are the first and best place to optimize code.

This works but...

I have encountered an error when I try this, and notice that an error only displays when status_id='0'.
Code:
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: admin/application.php
Line Number: 20
Line 20:
Code:
// view
<td>&lt;?= $a->status->name; ?&gt;</td>
I have read every post on this thread, and I can't quite remember if this has been covered. Should the id start from 1?

[eluser]m4rw3r[/eluser]
Does that particular application record have a status record attached in the db?
Because if not, $a->status would be false and you would receive the error you have got.

(and ids in db usually start at 1, btw)

[eluser]sofbas[/eluser]
Yes it does, when I look at the SQL generated in print_r, and I run it on MySQL, it returns the correct records e.g
Code:
SELECT  `status`.`id` AS  `status_id` ,  `status`.`name` AS  `status_name` ,  `status`.`description` AS  `status_description` ,  `applications`. *
FROM  `applications`
LEFT JOIN  `status` ON applications.status_id = status.id
WHERE  `applications`.`id` =  '1'
applications.id=1 is a record with a status_id=0

FYI using latest from SVN

Since I set the records in DB, starting at 1 is no issue.

[eluser]m4rw3r[/eluser]
Try and call idump($a) to see what it contains, and if the status record is present.

[eluser]sofbas[/eluser]
status comes back as NULL,
Code:
IR_record linked to applications(1), model: "application" { [status] => NULL [id] => string(1) "1" [surname] => string(7) "Surname" [name] => string(4) "Name" [gender] => string(1) "M" [dob] => string(10) "1999-11-30" [phone] => string(0) "" [mobile] => string(0) "" [email] => string(21) "[email protected]" [courses] => string(0) "" [created] => string(19) "2008-12-07 17:32:58" [revised] => string(19) "2008-12-16 23:08:29" [validation] => IR_validation_helper { [errors] => Array { } [record] => -RECURSION- } }

[eluser]m4rw3r[/eluser]
Ok, your zero there poses a problem because empty(0) evaluates to true.

I've corrected this problem by adding a check ($id != 0) to dbobj2ORM().

[eluser]sofbas[/eluser]
That was quick!

Thanks for all the work you have put into this library, it really is very useful, I am having a lot of fun working and learning with it.

[eluser]m4rw3r[/eluser]
I'm having a lot of fun writing it! Wink

And it is always fun to hear suggestions and copmpliments Smile

[eluser]cayasso[/eluser]
Hi is me again, is there any one that can help me out with this? Sad

Is there an easy way to set up self-related relationship in IR, so for example I have a table called Pages, A page can have related records in the same table related by a fk called parent_id.

So I have page “About Us” with id 1 as primary key but also have 2 more child pages with there own id but with parent id 1 because they should have the same content as they parent but in different languages.

PARENT
id: 1
title: About Us
language: en
resource_id: 0

CHILDS
id: 2
title: Acerca de
language: es
parent_id: 1

id: 3
title: Translated title
language: fr
parent_id: 1

How can I set this type of relationship thing with IR?

Thank you in advance

JB




Theme © iAndrew 2016 - Forum software by © MyBB