here. each Institution has many products each products have different stds. i want to filter it beased on selection
if(\Input::get('stds')){ $query->where('products.stds.name',\Input::get('std')); //Here is my problem. details below. }
if user selected std-A. then how i filter the result.
in view i used this.
$institution->products // this used over a loop, working properly, but i cant filter it, filtering causes error, my $query->get_one() become null.
an example is preferred, confused since a week.
simple queries like $query->where('products.gender',\Input::get('gender')); is working, because the gender is a column in products table. bit i want to filter the products with std. which is another table, also $query already have the relation of the same.
All data passed to a view is encoded, and that includes a query object. You should not have application logic in your views.
Filtering is application logic, and should happen in your controller.
ORM model objects are encoding aware, so you can pass those to a view without them being encoded. Their properties will encode on the fly when you access them.
You keep on saying filtering is a problem, have you checked why it is a problem? Have to checked which SQL is generated when you add the additional where()? Use the profiler to do so.
My guess: you can't use model aliases in dot-notation:
$query->where('products.students.name',\Input::get('std')); // This should work fine
if the "myname" is not exist, according to my thinking, i should get a null students data and valid institution object, because institution with id=5 is exist. but now i getting empty institution object. why, i only filtered on relation.
No, as I wrote before, by default the ORM generates standard joins (which in the case of MySQL is an INNER join), which means related table entries MUST exist.
If you want other join types, you have to define them either on the models' relation definition:
this is my debiginfo in profiler of same query, where i see there are 1 rows in t0 returned, but i cant get it, i getting only null. kindly help this matter.