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

You right, this is struct

CREATE TABLE `news_cat_lang` (
  `nc_id` int(11) NOT NULL,
  `title` varchar(100) default NULL,
  `lang_id` int(11) default NULL,
  KEY `id` (`nc_id`)

`nc_id` is not PK (Primary Key), cose `nc_id` non unique.

And next, this is really wrong in lib, cose

$d=$this->news_cat->find(1)->related('news_cat_lang')->get(); // Return one value in print_r, I write this in my previous post
$this->news_cat->find(1)->related('news_cat_lang')->count(); // Return 2, in the documentation this function return record count.

The thing is, ORM tools need a unique id to identify each record with. In your case isn't nc_id unique, but array(nc_id, lang_id) is.
And also, the count() method is correct, because there ARE 2 related rows in the table.
It is just your definition of id_col which is wrong (because nc_id isn't unique).
So set id_col to array(nc_id, lang_id) and it will work properly.

Thanks, i'll try it. Ok, this work. But i have next problem.

This code in print_r return valid value.
But i can't access to
I have error "Trying to get property of non-object", in print_r result returned in array, but if i have one value it may be return only class without array, or not? How i can access to variable without foreach?

Or i must do foreach in my model and return what i want in controller?

I had a similar issue, except it was with a more complicated query:
    select(array('person.*', 'students.*', 'student_course_enrolments.*'))->
    left_join('student_course_enrolments', 'courses.id = student_course_enrolments.course_id')->
    left_join('students', 'students.id = student_course_enrolments.student_id')->
    left_join('people AS person', 'students.person_id = person.id')->
    where('courses.id', $course_id);

// add custom search
idump($this->course->find_all(), '&nbsp;&nbsp;&nbsp;&nbsp;', '<br/>');die();

This showed only one record, when I know there should contain two.
After ensuring in the library that function dbobj2ORM() is receiving the correct records I tried adding the following before the above code:
and now I am getting two records!

The question is why?
And secondly, is there a way to use IR relations to get the same result? I initially tried adding joins, habtm through, and I couldn't do it.

NB I have removed code that is not relevant in the example, so there may be errors.

[quote author="m4rw3r" date="1233362245"]

So it won't help you with protection from Cross site scripting (use htmlspecialchars(), input filtering and similar), but it makes it possible to save html and javasctipt in the db without fear of db errors Tongue.[/quote]

In IR_record->load_postdata, the line
$this->$col = $CI->input->post($field);
could be changed to
$this->$col = $CI->input->post($field, true);
to enable the XSS filter.

I use your validation behaviour form builder extensively and so added that in for myself.

Just a quick answer on skipping the foreach loop:
$obj->title = 'foo';
$array = array($obj);

// $array is the return value from an IR method:
echo array_shift($array)->title;
Getting to the other problem(s) when I have more time, probably tomorrow.

EDIT: end() or current() can also be used in place of array_shift()

Thanks, very nice trick =)


Please forgive me if I am asking about something that has already been discussed.

I have used an ORM called ORM.NET (Recovering C# guy...) in which you could get a collection from the DB, with related records, i.e. many users AND all their blogs, iterate the users and in turn iterate the related records, making changes to them as you went along and then at the end, the command 'DataManager.CommitAll();' and presto all was written to the DB. So you see I am spoiled... Did I miss this functionality in IR or is it not there yet? Or am i just a big baby for wanting it?...

Thank you for your time. Smile


PS you could also query any row for it's state changed/unchanged/commited etc.

That isn't possible to do neatly with PHP 4, so it will be implemented when I move to PHP 5.
And that will be within this year, if my experiments with a new db abstraction will play out satisfactory.

PS. the work on the manual is still going slow Sad

Theme © iAndrew 2016 - Forum software by © MyBB