CodeIgniter Forums
(Datamapper) Where_join_field->Error 1054 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: (Datamapper) Where_join_field->Error 1054 (/showthread.php?tid=40409)



(Datamapper) Where_join_field->Error 1054 - El Forum - 04-07-2011

[eluser]liebgott[/eluser]
Hello!

My models:

Student
Code:
<?php
class Student extends DataMapper {

    var $table = "students";

    public $has_many = array('course');

    public function __construct()
    {
        // model constructor
        parent::__construct();
    }
}

Course:
Code:
<?php
class Course extends DataMapper {

    var $table = "courses";

    public $has_many = array('student');

    public function __construct()
    {
        // model constructor
        parent::__construct();
    }
}

I'm stuck with this error...:

Code:
A Database Error Occurred

Error Number: 1054

Unknown column 'courses_students.pagado' in 'where clause'

SELECT * FROM (`courses`) WHERE `courses_students`.`pagado` = 0

...when in the controller I only want to check if it's all ok

Code:
$numero = new Course();
        $numero->where_join_field('student', 'pagado' , FALSE)->get();

        foreach ($numero as $n){
            echo $n;
        }

My students_courses table:

Code:
id | student_id | course_id | pagado

1        1            1           1
2        2            1           0

What i'm missing???

Thanks!!


(Datamapper) Where_join_field->Error 1054 - El Forum - 04-07-2011

[eluser]WanWizard[/eluser]
You're missing the fact that you don't join anything. The "Student" object isn't part of your question, so no JOIN is added to the query, and the table doesn't exist.

Try
Code:
$numero->select('course.*')->student->where_join_field('student', 'pagado' , FALSE)->get();



(Datamapper) Where_join_field->Error 1054 - El Forum - 04-08-2011

[eluser]liebgott[/eluser]
Now i'm getting this

Code:
An Error Was Encountered

Unable to relate student with student.



(Datamapper) Where_join_field->Error 1054 - El Forum - 04-08-2011

[eluser]WanWizard[/eluser]
Hmmm...

I'm not in a position to test anything at the moment. I have to think about this scenario.


(Datamapper) Where_join_field->Error 1054 - El Forum - 08-07-2011

[eluser]swatkins[/eluser]
[quote author="liebgott" date="1302263964"]Now i'm getting this

Code:
An Error Was Encountered

Unable to relate student with student.
[/quote]

I'm sure you've figured this out, but I'll post here for others having the same problem. Your code:

Code:
$numero->select('course.*')->student->where_join_field('student', 'pagado' , FALSE)->get();

is trying to relate student -> student because of the chainability of datamapper. When you call 'where_join_field', you're actually calling that on 'student' because that's the last object you've referenced in the chain when you call 'where_join_field'. Therefore, you need to specify the relationship back to $numero in 'where_join_field'.

Code:
$numero->select('course.*')->student->where_join_field($numero, 'pagado' , FALSE)->get();