Firstly I explain my issue :
I have two tables Job and JobCategory :
job:
-------------------------------------------------
| id | category_job_id | job_name | keywords |
-------------------------------------------------
JobCategory:
-------------------------
| id | categoty_name |
-------------------------
tho two tables is related by foreign key "category_job_id".
In this application I'm using Propel ORM. I hoped to make search using three fields keywords, job_name and category_name.
The first field is keywords is "input" who I can write keywords, the second field is Category_name is a "select", list of category. The third field is Job_name and is a "select", list of Job name, and if is not empty the keywords fields will be ignored.
I make function of search like this, but it doesn't work for me:
public function searchFilter($job,$category,$keyword)
{
$order = isset($this->order) ? $this->order : Criteria::ASC;
$job = '%' .$job. '%';
$category = '%' .$category. '%';
$c = new Criteria();
$c->addJoin(JobPeer::CATEGORY_JOB_ID, JobCategoryPeer::ID);
if((null !== $category) AND ($category !== ""))
{
$c->addOr(JobCategoryPeer::CATEGORY_NAME,$category, Criteria::LIKE);
}
if((null !== $job) AND ($job !== ""))
{
$c->addOr(JobPeer::JOB_NAME,$job, Criteria::LIKE);
}
$query = JobQuery::create(null, $c)
->joinWith('Job.JobCategory')
->orderByDateOfJob($order);
if((null !== $keyword) AND ($keyword !== "")){
$keyword = '%' .$keyword. '%';
$query->filterByKeywords($keyword, Criteria::LIKE);
}
$results = $query->find();
return $results;
}
But the search is all cases is wrong!
job_category
, notJobCategory
- the latter is your corresponding model class. I should thinkcategoty_name
should becategory_name
too. – halfertoString
method (or similar) you can apply to$query
, which will give you the SQL it has generated. This is invaluable for debugging. – halfer