2011/5/4 passkey1...@gmail.com <passkey1...@gmail.com>: > Hi Michał, > Thank you for your answer. I think that's a good solution. How would you > deal with offset and limit if I want to have a pager?. With the intersection > of multiple arrays, offset does not make sense anymore, doesn't it? > Tuan
I do not see any problem here - just pass $product_ids as a parameter to the pager and add there $q->andWhereIn('p.id', $product_ids); > > 2011/5/4 Michał Piotrowski <mkkp...@gmail.com> >> >> Hi, >> >> 2011/5/4 passkey1...@gmail.com <passkey1...@gmail.com>: >> > Hi there, >> > I'd like to ask you guys a question when you have to deal with a VERY >> > complex query. >> > Use case: >> > An e-commerce website with integrated social network. User could have >> > many >> > friends on that website. For each user, I have to list all products >> > which: >> > - are marked as featured (sponsored products, for instance). >> > - have already been purchased by at least one of his friends. >> > - he did not purchase yet. >> > .... >> > - are available in his country >> > .... >> > and so on. >> > >> > For these kinds of complex query, I would not imagine that a SQL query >> > is an >> > appropriate solution. My thought was to make a simple query, then do >> > some >> > processing in php to filter out all records that do not satisfy the >> > condition. >> > >> > How did you guys think of that solution? Have you ever dealt with such >> > kind >> > of query? >> >> I usually do, so that I use intersections >> >> $this->companys = >> Doctrine_Core::getTable('Company')->getCompanysHydrate(); >> $this->companys_array = array(); >> foreach ($this->companys as $this->company) { >> $this->companys_array[] = $this->company['id']; >> } >> >> $this->companys_search = >> >> Doctrine_Core::getTable('Company')->getCompanysByNameLikeHydrate($this->search); >> $this->companys_search_array = array(); >> >> foreach ($this->companys_search as $this->company_search) { >> $this->companys_search_array[] = $this->company_search['id']; >> } >> >> >> (Other criteria) >> >> >> >> Now we take a common part >> >> $this->company_result_ids = $this->companys_array; >> if ($this->search) { >> $this->company_result_ids = >> array_intersect($this->company_result_ids, >> $this->companys_search_array); >> } >> >> >> >> and now the result of the common part >> >> $this->companys = >> >> Doctrine_Core::getTable('Company')->getCompanysByIds($this->company_result_ids); >> >> >> > >> > Thanks, >> > Tuan >> > >> > -- >> > If you want to report a vulnerability issue on symfony, please send it >> > to >> > security at symfony-project.com >> > >> > You received this message because you are subscribed to the Google >> > Groups "symfony users" group. >> > To post to this group, send email to symfony-users@googlegroups.com >> > To unsubscribe from this group, send email to >> > symfony-users+unsubscr...@googlegroups.com >> > For more options, visit this group at >> > http://groups.google.com/group/symfony-users?hl=en >> > >> >> >> >> -- >> Best regards, >> Michal >> >> http://eventhorizon.pl/ >> >> -- >> If you want to report a vulnerability issue on symfony, please send it to >> security at symfony-project.com >> >> You received this message because you are subscribed to the Google >> Groups "symfony users" group. >> To post to this group, send email to symfony-users@googlegroups.com >> To unsubscribe from this group, send email to >> symfony-users+unsubscr...@googlegroups.com >> For more options, visit this group at >> http://groups.google.com/group/symfony-users?hl=en > > -- > If you want to report a vulnerability issue on symfony, please send it to > security at symfony-project.com > > You received this message because you are subscribed to the Google > Groups "symfony users" group. > To post to this group, send email to symfony-users@googlegroups.com > To unsubscribe from this group, send email to > symfony-users+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/symfony-users?hl=en > -- Best regards, Michal http://eventhorizon.pl/ -- If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en