Jeremy Burns
http://www.classoutfit.com
On 1 Nov 2011, at 09:43, WebbedIT wrote:
@Chris: Please no, not another person advocating the use of $this-query()! Although this one is really special as anytime you join twomodels you give up and revert to running your own SQL?!?
Just because you can't get your head around associating models
together and running Model::find (should get your head around
containable too) does not mean you should recommend to others early in
the learning curve to follow your cop-out path.
There are so many reasons to learn how to use Cake properly and it
certainly does not make life harder, in fact you could not be further
from the truth. OK there are some circumstances where you need to
learn how to leverage Model::find a little, but these are very few and
far between and the benefits of having your data arrays passed back in
a manner that the Form helper and Model::save expects them in saves
you a ton of time.
Please go back to the book and take the time to learn it and don't
advise others to give up on it.
Paul.
On Oct 31, 9:07 am, Chris Cinelli
<chris.cine...@formativelearning.com> wrote:We have complicated queries that span across 8 tables. We decided to usepure SQL code. We defined our data source and run SQL through it definingour custom methods in the model that execute the query. If the query isjust on one table we use the ORM but pure SQL pretty much in the othercases. The purpouse of the ORM layer is to make things easier. If you makeit more complicated, why are you doing it?On Oct 31, 2011 1:55 AM, "WebbedIT" <p...@webbedit.co.uk> wrote:Without seeing any of your code (model associations would have beennice) I logically assume you are using Article HABTM Tag.If so this does not create a model for the join table, but insteadputs in place some automagic to allow you to link many-to-many recordsbetween the two models. As such you can't run a find on the joinmodel, which is what you would have to do to be able to haveconditions spanning the three tables.Your options are to use unbind and bind to force joins that you canuse:http://nuts-and-bolts-of-cakephp.com/2008/08/06/habtm-and-join-tricke...Or, my preferred option is to create a model for join tablesArticle hasMany ArticleTagTag hasMany ArticleTagArticleTag belongsTo Article, TagThis allows you to easily add extra fields into your join table and torun $this->Article->ArticleTag->find('all', array('conditions'=>array('Article.is_read'=>0,'Article.status'=>1,'Tag.name'=>'cakephp')));HTH, Paul.P.S. Notice how I have changed some of your field names and values.Your isRead field should be lowercased and underscored and if boolenuse tinyint(1) with 0 and 1. When searching for articles by tag youwould normally recieve the tagname in the request (much better forseo) so to query by Tag.id would require an extra find that I wouldsay is unneccessary when you can filter by Tag.name (especially if youhave the name field unique indexed). I would also switchArticle.status for numerical values, ideally with a lookup table soyou can easily add/edit status text across all articles.On Oct 30, 8:50 am, SERKAN TURAN <serkantu...@gmail.com> wrote:Hi,I have an query and I could not figure it out what is the cakephp form ofit.query:-------------------------------------------SELECT *FROMtags`INNER JOIN `tags_articles` ON (`tags`.`id` = `tags_articles`.`tag_id`)INNER JOIN `articles` ON (`tags_articles`.`article_id` =`articles`.`id`)WHERE`articles`.`isRead` = 'Not' AND`tags`.`id` = 3 AND`articles`.`status` = 'New'ORDER BY`articles`.`name` DESC----------------------------------------------------------------------------------------------Thnks..ST--Our newest site for the community: CakePHP Video Tutorialshttp://tv.cakephp.orgCheck out the new CakePHP Questions sitehttp://ask.cakephp.organd helpothers with their CakePHP related questions.To unsubscribe from this group, send email tocake-php+unsubscribe@googlegroups.com For more options, visit this groupathttp://groups.google.com/group/cake-php
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
No comments:
Post a Comment