Re: Finding related articles
I completely agree, both with the point about it being difficult to use Cake for advanced applications (or just non-standard CRUD sites) without prior knowledge of SQL, and about not picking up bad habits by developing within an MVC framework from the get-go. Personally, I'm not as familiar with SQL as I'd like to be either (don't know how to use triggers, stored procedures, build indexes, create constraints, etc.), even though I've been developing with it for over 7 years, as I've never taken a formal course on database design/development/administration. But I have the dev.mysql.com (as well as php.net, jquery.com, Cake API/Cookbook, MDC, etc.) search tool install with search keywords configured so that I can just type "mysql distinct" into the Firefox address bar, and it will search the online MySQL documentation for the DISTINCT keyword--it doesn't work quite as well as php.net's search function, which will automatically take you to the page for that function/class/topic, but it still saves me a lot of time since I'm looking up stuff in the MySQL manual all day long. MySQL's online documentation can be quite dense at times, as it also assumes that you have formal training in SQL and relational databases, but the user comments are pretty helpful and often includes example code. But the best way to learn (aside from taking an academic course) is just to practice writing lots of MySQL queries using the command- line client or write practice PHP+MySQL apps using manual queries instead of Cake's model functions. You should do this at least until you're proficient enough in SQL that you can write your Cake application without the use of Cake's database abstraction (e.g. know how to use SELECT, INSERT, UPDATE, DELETE, as well as basic uses of joins and even subqueries). Once you've done that, then you can let Cake handle most of the menial queries and use GUI clients to administer your database. On May 11, 11:56 pm, WebbedIT wrote: > It is going to be a little more difficult for you coming to this > without any prior knowledge of databases. However, I wish I had > worked within the constraints of this framework (OOP/MVC Design > Pattern) before I had the chance to teach myself a lot of bad habits > so you have that going for you. > > Whilst book.cakephp.org does mention the use of DISTINCT and GROUP > etc. it is likely to cover them as if you already know what they do. > It may be worthwhile reading through some MySQL tutorials (I assume > you're using MySQL) just to get your head around the possibilities > open to you. > > I have never read through a tutorial from start to finish but a quick > Google found this one which seems to cover most of the functions: > > http://www.tizag.com/mysqlTutorial/ > > someone else may be able to recommend a better one though. > > HTH > > Paul. > > Check out the new CakePHP Questions sitehttp://cakeqs.organd help others with > their CakePHP related questions. > > You received this message because you are subscribed to the Google Groups > "CakePHP" group. > To post to this group, send email to cake-php@googlegroups.com > To unsubscribe from this group, send email to > cake-php+unsubscr...@googlegroups.com For more options, visit this group > athttp://groups.google.com/group/cake-php?hl=en Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Finding related articles
It is going to be a little more difficult for you coming to this without any prior knowledge of databases. However, I wish I had worked within the constraints of this framework (OOP/MVC Design Pattern) before I had the chance to teach myself a lot of bad habits so you have that going for you. Whilst book.cakephp.org does mention the use of DISTINCT and GROUP etc. it is likely to cover them as if you already know what they do. It may be worthwhile reading through some MySQL tutorials (I assume you're using MySQL) just to get your head around the possibilities open to you. I have never read through a tutorial from start to finish but a quick Google found this one which seems to cover most of the functions: http://www.tizag.com/mysqlTutorial/ someone else may be able to recommend a better one though. HTH Paul. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Finding related articles
Look in the CakePHP book at: http://book.cakephp.org/view/1017/Retrieving-Your-Data and browse through each section, so that you can find the examples for DISTINCT, grouping, OR, etc. Complex find at: http://book.cakephp.org/view/1017/Retrieving-Your-Data#Complex-Find-Conditions-1030 as well as grouping described in: http://book.cakephp.org/view/1017/Retrieving-Your-Data#find-1018 Enjoy, John On May 11, 6:59 am, jthommo wrote: > Thanks Paul, > > I'll give it a go. > > You're right - the teknoid.wordpress.com site has a good bunch of > HABTM stuff on it, in > particular:http://teknoid.wordpress.com/2008/08/06/habtm-and-join-trickery-with-... > > I think what I'm really missing is more detail on the various > parameters you can stick into find(). In your example, you've used > DISTINCT and OR and in the linked-to article they use 'group'. Where > are these coming from? Am I missing this as I'm new to SQL in general? > The book isn't exactly detailed in this area... > > Thanks a lot, > Jeremy > [snip] Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Finding related articles
Thanks Paul, I'll give it a go. You're right - the teknoid.wordpress.com site has a good bunch of HABTM stuff on it, in particular: http://teknoid.wordpress.com/2008/08/06/habtm-and-join-trickery-with-cakephp/ I think what I'm really missing is more detail on the various parameters you can stick into find(). In your example, you've used DISTINCT and OR and in the linked-to article they use 'group'. Where are these coming from? Am I missing this as I'm new to SQL in general? The book isn't exactly detailed in this area... Thanks a lot, Jeremy On May 10, 5:38 pm, WebbedIT wrote: > Firstly, welcome to the community and to the joys of CakePHP > > Secondly, HABTM is where a lot of people tend to start tripping over > themselves as it's really a convenience method to join 3 tables > together with minimal coding and doesn't always have the flexibility > of what should ideally be a > > ModelA hasMany JoinModel > ModelB hasMany JoinModel > JoinModel belongsTo ModelA > JoinModel belongsTo ModelB > > The book touches on finding recipes by tag very lightly on > page:http://book.cakephp.org/view/83/hasAndBelongsToMany-HABTM > > However to really get my head around HABTM I spent some time reading > Teknoids articles on the subjecthttp://teknoid.wordpress.com/?s=habtm > > He also created a Habtamable behaviour which I am yet to try using > myself:http://teknoid.wordpress.com/2009/09/26/habtamable-behavior/ > > The book example gives you a couple of examples of how to fetch data > relating to a certain tag and Teknoid expands on those. > > I think from what you are saying and looking at the book's example you > should be able to get close to what you want by using > > $this->Article->Tag->find('all', array('conditions'=>array( > 'OR'=>array( > 'Tag.name'=>'Tag1', > 'Tag.name'=>'Tag2', > 'Tag.name'=>'Tag3' > ) > ))); > > Grouping your conditions in an OR array will fetch any article that > matches any of the tags rather than all of them, but then you will > have to tackle the problem that this will not fetch UNIQUE articles. > You will have to experiment with something along the lines of > > $this->Article->Tag->find('all', array( > 'fields'=>array('DISTINCT Article.id', 'Article.title', > 'Article.???') > 'conditions'=>array( > 'OR'=>array( > 'Tag.name'=>'Tag1', > 'Tag.name'=>'Tag2', > 'Tag.name'=>'Tag3' > )) > )); > > Hope this helps, > > Paul > > Check out the new CakePHP Questions sitehttp://cakeqs.organd help others with > their CakePHP related questions. > > You received this message because you are subscribed to the Google Groups > "CakePHP" group. > To post to this group, send email to cake-php@googlegroups.com > To unsubscribe from this group, send email to > cake-php+unsubscr...@googlegroups.com For more options, visit this group > athttp://groups.google.com/group/cake-php?hl=en Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Finding related articles
Thanks Paul, I'll give it a go. You're right - the teknoid.wordpress.com site has a good bunch of HABTM stuff on it, in particular: http://teknoid.wordpress.com/2008/08/06/habtm-and-join-trickery-with-cakephp/ I think what I'm really missing is more detail on the various parameters you can stick into find(). In your example, you've used DISTINCT and OR and in the linked-to article they use 'group'. Where are these coming from? Am I missing this as I'm new to SQL in general? The book isn't exactly detailed in this area... Thanks a lot, Jeremy On May 10, 5:38 pm, WebbedIT wrote: > Firstly, welcome to the community and to the joys of CakePHP > > Secondly, HABTM is where a lot of people tend to start tripping over > themselves as it's really a convenience method to join 3 tables > together with minimal coding and doesn't always have the flexibility > of what should ideally be a > > ModelA hasMany JoinModel > ModelB hasMany JoinModel > JoinModel belongsTo ModelA > JoinModel belongsTo ModelB > > The book touches on finding recipes by tag very lightly on > page:http://book.cakephp.org/view/83/hasAndBelongsToMany-HABTM > > However to really get my head around HABTM I spent some time reading > Teknoids articles on the subjecthttp://teknoid.wordpress.com/?s=habtm > > He also created a Habtamable behaviour which I am yet to try using > myself:http://teknoid.wordpress.com/2009/09/26/habtamable-behavior/ > > The book example gives you a couple of examples of how to fetch data > relating to a certain tag and Teknoid expands on those. > > I think from what you are saying and looking at the book's example you > should be able to get close to what you want by using > > $this->Article->Tag->find('all', array('conditions'=>array( > 'OR'=>array( > 'Tag.name'=>'Tag1', > 'Tag.name'=>'Tag2', > 'Tag.name'=>'Tag3' > ) > ))); > > Grouping your conditions in an OR array will fetch any article that > matches any of the tags rather than all of them, but then you will > have to tackle the problem that this will not fetch UNIQUE articles. > You will have to experiment with something along the lines of > > $this->Article->Tag->find('all', array( > 'fields'=>array('DISTINCT Article.id', 'Article.title', > 'Article.???') > 'conditions'=>array( > 'OR'=>array( > 'Tag.name'=>'Tag1', > 'Tag.name'=>'Tag2', > 'Tag.name'=>'Tag3' > )) > )); > > Hope this helps, > > Paul > > Check out the new CakePHP Questions sitehttp://cakeqs.organd help others with > their CakePHP related questions. > > You received this message because you are subscribed to the Google Groups > "CakePHP" group. > To post to this group, send email to cake-php@googlegroups.com > To unsubscribe from this group, send email to > cake-php+unsubscr...@googlegroups.com For more options, visit this group > athttp://groups.google.com/group/cake-php?hl=en Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Finding related articles
Firstly, welcome to the community and to the joys of CakePHP Secondly, HABTM is where a lot of people tend to start tripping over themselves as it's really a convenience method to join 3 tables together with minimal coding and doesn't always have the flexibility of what should ideally be a ModelA hasMany JoinModel ModelB hasMany JoinModel JoinModel belongsTo ModelA JoinModel belongsTo ModelB The book touches on finding recipes by tag very lightly on page: http://book.cakephp.org/view/83/hasAndBelongsToMany-HABTM However to really get my head around HABTM I spent some time reading Teknoids articles on the subject http://teknoid.wordpress.com/?s=habtm He also created a Habtamable behaviour which I am yet to try using myself: http://teknoid.wordpress.com/2009/09/26/habtamable-behavior/ The book example gives you a couple of examples of how to fetch data relating to a certain tag and Teknoid expands on those. I think from what you are saying and looking at the book's example you should be able to get close to what you want by using $this->Article->Tag->find('all', array('conditions'=>array( 'OR'=>array( 'Tag.name'=>'Tag1', 'Tag.name'=>'Tag2', 'Tag.name'=>'Tag3' ) ))); Grouping your conditions in an OR array will fetch any article that matches any of the tags rather than all of them, but then you will have to tackle the problem that this will not fetch UNIQUE articles. You will have to experiment with something along the lines of $this->Article->Tag->find('all', array( 'fields'=>array('DISTINCT Article.id', 'Article.title', 'Article.???') 'conditions'=>array( 'OR'=>array( 'Tag.name'=>'Tag1', 'Tag.name'=>'Tag2', 'Tag.name'=>'Tag3' )) )); Hope this helps, Paul Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en