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

[eluser]MisterX[/eluser]
You right, this is struct

Code:
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`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8

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

And next, this is really wrong in lib, cose

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

[eluser]m4rw3r[/eluser]
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.

[eluser]MisterX[/eluser]
Thanks, i'll try it. Ok, this work. But i have next problem.

Code:
$d=&$this->news_cat->find(1)->related('news_cat_lang')->where('lang_id',1)->get();
This code in print_r return valid value.
But i can't access to
Code:
$d->title
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?

[eluser]MisterX[/eluser]
Or i must do foreach in my model and return what i want in controller?

[eluser]sofbas[/eluser]
I had a similar issue, except it was with a more complicated query:
Code:
$this->course->
    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
$this->course->set_student_search($this->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:
Code:
$this->course->use_duplicates(true);
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.

[eluser]sofbas[/eluser]
[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
Code:
$this->$col = $CI->input->post($field);
could be changed to
Code:
$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.

[eluser]m4rw3r[/eluser]
Just a quick answer on skipping the foreach loop:
Code:
$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()

[eluser]MisterX[/eluser]
Thanks, very nice trick =)

[eluser]ephroni[/eluser]
Hi,

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

Joel

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

[eluser]m4rw3r[/eluser]
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