Re: [Radiant] Console question on Radiant
Relax, Anton. I simply wrote that b/c Sean said others on the list might know the SQL method. On Tue, Feb 9, 2010 at 10:38 AM, Anton Aylward wrote: > banane said the following on 02/09/2010 12:34 PM: > >> In pure SQL it would be: >> >> [snip] > > BTDT. Deperately want to avoid going back! > >> I'm not well versed enough in Rails to know how to do this, ha! Isn't >> there a "sql" option in ActiveRecord where you can just push in db-sql >> and not worry about Rails doing the joins? > > The whole point was to use the rails _console_ and use the > object-relational mapping. If I wanted a SQL solution I wouldn't have > asked in a Ruby/Rails/Radiant forum :-) > > I like the idea of constructs such as > > Page.find(:all. :conditions .).name > as an extrapolation of > Page.name > > This is "Object" stuff, which is a lot more natural to an natural > language user than the half-RPN nature of SQL. > > SQL is really the assembly code of database programming. > The Rails object relational mapping is the HLL. > > If you love programming in assembly code I'm not going to stop you. > But most of the programmers I know use at least C or C++, if not Perl or > PHP or Python, and Ruby is one of the more H of the HLLs. > ___ > Radiant mailing list > Post: Radiant@radiantcms.org > Search: http://radiantcms.org/mailing-list/search/ > List Site: http://lists.radiantcms.org/mailman/listinfo/radiant > Radiant: http://radiantcms.org > Extensions: http://ext.radiantcms.org > ___ Radiant mailing list Post: Radiant@radiantcms.org Search: http://radiantcms.org/mailing-list/search/ List Site: http://lists.radiantcms.org/mailman/listinfo/radiant Radiant: http://radiantcms.org Extensions: http://ext.radiantcms.org
Re: [Radiant] Console question on Radiant
banane said the following on 02/09/2010 12:34 PM: > In pure SQL it would be: > > [snip] BTDT. Deperately want to avoid going back! > I'm not well versed enough in Rails to know how to do this, ha! Isn't > there a "sql" option in ActiveRecord where you can just push in db-sql > and not worry about Rails doing the joins? The whole point was to use the rails _console_ and use the object-relational mapping. If I wanted a SQL solution I wouldn't have asked in a Ruby/Rails/Radiant forum :-) I like the idea of constructs such as Page.find(:all. :conditions .).name as an extrapolation of Page.name This is "Object" stuff, which is a lot more natural to an natural language user than the half-RPN nature of SQL. SQL is really the assembly code of database programming. The Rails object relational mapping is the HLL. If you love programming in assembly code I'm not going to stop you. But most of the programmers I know use at least C or C++, if not Perl or PHP or Python, and Ruby is one of the more H of the HLLs. ___ Radiant mailing list Post: Radiant@radiantcms.org Search: http://radiantcms.org/mailing-list/search/ List Site: http://lists.radiantcms.org/mailman/listinfo/radiant Radiant: http://radiantcms.org Extensions: http://ext.radiantcms.org
Re: [Radiant] Console question on Radiant
In pure SQL it would be: select * from page where page_part_id in ( select page_part_id from page_parts where name = "body" and content is null ) Or you could do a join select * from page p, page_part p1 where p.page_part_id = p1.page_part_id and p1.name="body" p1.content is null I'm not well versed enough in Rails to know how to do this, ha! Isn't there a "sql" option in ActiveRecord where you can just push in db-sql and not worry about Rails doing the joins? ___ Radiant mailing list Post: Radiant@radiantcms.org Search: http://radiantcms.org/mailing-list/search/ List Site: http://lists.radiantcms.org/mailman/listinfo/radiant Radiant: http://radiantcms.org Extensions: http://ext.radiantcms.org
Re: [Radiant] Console question on Radiant
Anton, You were close. 'a' will be an array of PagePart instances. Try: a.map(&:page).uniq There's a way to do this query in the database but my brain is way outside SQL lately, so maybe someone on the mailing list can help. Sean On 2/8/10 9:13 PM, Anton Aylward wrote: > I'm not a programmer, though I have these flights of fancy! > > I'm trying to find what parts of a radiant site haven't been written. > My idea was to look for the page-parts that are blank and what pages > they belong to. > > I figured out > > a = PagePart.find( :all, > :conditions => { :content => "", :name => "body" } ) > > that gives me the list of empty part. > > Now I thought I could have done a join .. > >. ).Page.name > > or at very least > >. ).page_id > > to get the array and then > > a.each { |p| Page.find(:all, :conditions => { :id => p.page_id } ) } > > > but it seems not. > > I've tried > > a = PagePart.find( :all, > :conditions => { :content => "", > :name => "body" } ) do |p| > Page.find(p.page_id).title > end > > Which struck me as logical, but it returned the same array > > > I even tried the other way round but wasn't sure how to "go forward" > So I ended up with > > b = [] > a = PagePart.find( :all, :conditions => { > :content => "", > :name => "body" } ).each do |p| >b<< Page.find( p.page_id).title > end > > Which gives me "b", but seems awkward > > An how do I get that lsited? > > > > > > > > ___ Radiant mailing list Post: Radiant@radiantcms.org Search: http://radiantcms.org/mailing-list/search/ List Site: http://lists.radiantcms.org/mailman/listinfo/radiant Radiant: http://radiantcms.org Extensions: http://ext.radiantcms.org