House belongs_to Community. House has_many Images. Community has_many Houses. Communities belong_to Contractors. When displaying a Community, I need to get 3 random Images of Houses that have been built by the Contractor of said Community. How would I do that? Thanks, Joe
On 4/20/05, Erich Ocean <erich-O4CYnKbOxv6QWHG76I6BsA@public.gmane.org> wrote:> Search the archives.Thanks.. but can you be a little bit more specific? What am I searching for? Joe> > On Apr 20, 2005, at 5:38 PM, Joe Van Dyk wrote: > > > House belongs_to Community. > > House has_many Images. > > Community has_many Houses. > > Communities belong_to Contractors. > > > > When displaying a Community, I need to get 3 random Images of Houses > > that have been built by the Contractor of said Community. > > > > How would I do that? > > > > Thanks, > > Joe > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > >
On 4/21/05, Joe Van Dyk <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 4/20/05, Erich Ocean <erich-O4CYnKbOxv6QWHG76I6BsA@public.gmane.org> wrote: > > Search the archives. > > Thanks.. but can you be a little bit more specific? What am I searching for? > > Joe > > > > > On Apr 20, 2005, at 5:38 PM, Joe Van Dyk wrote: > > > > > House belongs_to Community. > > > House has_many Images. > > > Community has_many Houses. > > > Communities belong_to Contractors. > > > > > > When displaying a Community, I need to get 3 random Images of Houses > > > that have been built by the Contractor of said Community. > > > > > > How would I do that?A few questions: 1) Does it matter if the images are from the same house? 2) What about from the same community? 3) Contractor has_many communities? -- Cheers Koz
On 4/21/05, Michael Koziarski <koziarski-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 4/21/05, Joe Van Dyk <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > On 4/20/05, Erich Ocean <erich-O4CYnKbOxv6QWHG76I6BsA@public.gmane.org> wrote: > > > Search the archives. > > > > Thanks.. but can you be a little bit more specific? What am I searching for? > > > > Joe > > > > > > > > On Apr 20, 2005, at 5:38 PM, Joe Van Dyk wrote: > > > > > > > House belongs_to Community. > > > > House has_many Images. > > > > Community has_many Houses. > > > > Communities belong_to Contractors. > > > > > > > > When displaying a Community, I need to get 3 random Images of Houses > > > > that have been built by the Contractor of said Community. > > > > > > > > How would I do that? > > A few questions: > > 1) Does it matter if the images are from the same house?No. Returned mages can come from the same house.> 2) What about from the same community?Returned images can be from the same community.> 3) Contractor has_many communities?Yes. (There''s also one last requirement... there''s an additional column in the Image table called ''ok_to_randomly_display''. If its value is a 1, then it''s valid for returning. If it''s not a 1, then it shouldn''t be returned.) I suppose I could do this by getting all the Communities that are associated with each Contractor. And then get all the Houses that are associated with those Communities. And then get all the Images from those Houses that have ok_to_randomly_display == 1. And then return three random ones of those. :-) But that''s probably not very efficient. Thanks again, Joe
On 21.4.2005, at 03:38, Joe Van Dyk wrote:> House belongs_to Community. > House has_many Images. > Community has_many Houses. > Communities belong_to Contractors. > > When displaying a Community, I need to get 3 random Images of Houses > that have been built by the Contractor of said Community. > > How would I do that?Image.find(:all, :conditions => ["images.ok_to_randomly_display = 1 and c.id = ?", @contractor.id], :joins => "inner join houses on image.house_id = houses.id inner join communities on house.community_id = communities.id inner join contractors c on community.contractor_id = c.id") There''s probably some typos but you get the idea. Read http://rails.rubyonrails.com/classes/ActiveRecord/Base.html#M000650 for more info on the new find syntax. As for the random part of your wish, it was just discussed so search for "random" in the archives. //jarkko> > Thanks, > Joe > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
I posed this problem earlier, but since I''ve narrowed the scope, I thought I''d start a new thread. I''m trying to create scaffold code for a simple table. I''m working off of a local mysql server on a development box that I use every day, so I''m very familiar with the environment. When I run:> ruby script/generate scaffold CategoryThe script fails with this error message: error Before updating scaffolding from new DB schema, try creating a tab le for your model (Categoty) The table is there (check, and re-checked 10 times), but what is odd, it doesn''t matter what I have my db password set to in my database.yml file... If it is blank, the script fails with: #28000Access denied for user ''mike''@''localhost'' (using password: NO) Which is what I would expect... but when I have my password, or anything else, I get the preceding error. So, it seems weird that the generate script isn''t failing with an error stating that my password is wrong. I''ve upgraded to 0.12.1... Please help.
Mike, On 21.4.2005, at 15:22, Mike Evans wrote:> I posed this problem earlier, but since I''ve narrowed the scope, I > thought I''d > start a new thread. > > I''m trying to create scaffold code for a simple table. I''m working > off of a > local mysql server on a development box that I use every day, so I''m > very > familiar with the environment. > > When I run: > >> ruby script/generate scaffold Category > > The script fails with this error message: > error Before updating scaffolding from new DB schema, try > creating a tab > le for your model (Categoty)This sounds like a typo (Categoty). The error above means that rails can login to your db but that the table doesn''t exist. //jarkko> > The table is there (check, and re-checked 10 times), but what is odd, > it doesn''t > matter what I have my db password set to in my database.yml file... If > it is > blank, the script fails with: > #28000Access denied for user ''mike''@''localhost'' (using password: NO) > Which is what I would expect... but when I have my password, or > anything else, I > get the preceding error. > > So, it seems weird that the generate script isn''t failing with an > error stating > that my password is wrong. > > I''ve upgraded to 0.12.1... Please help. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On 4/21/05, Mike Evans <mike-u4reGlrcmwqg/H9aKuUo6lBd07bTekyB@public.gmane.org> wrote:> I posed this problem earlier, but since I''ve narrowed the scope, I thought I''d > start a new thread. > > I''m trying to create scaffold code for a simple table. I''m working off of a > local mysql server on a development box that I use every day, so I''m very > familiar with the environment. > > When I run: > > > ruby script/generate scaffold Category > > The script fails with this error message: > error Before updating scaffolding from new DB schema, try > creating a tab > le for your model (Categoty) > > The table is there (check, and re-checked 10 times), but what is odd, > it doesn''t > matter what I have my db password set to in my database.yml file... If it is > blank, the script fails with: > #28000Access denied for user ''mike''@''localhost'' (using password: NO) > Which is what I would expect... but when I have my password, or > anything else, I > get the preceding error. > > So, it seems weird that the generate script isn''t failing with an error > stating > that my password is wrong. > > I''ve upgraded to 0.12.1... Please help. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >What table name are you trying to use? In this case, a model with the name ''Category'' should have a table called ''categories'' in the db. Dave -- Dave Goodlad dgoodlad-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org or dave-eHfbeeWWzZOw5LPnMra/2Q@public.gmane.org http://david.goodlad.ca/
Quoting David Goodlad <dgoodlad-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> On 4/21/05, Mike Evans <mike-u4reGlrcmwqg/H9aKuUo6lBd07bTekyB@public.gmane.org> wrote: >> I posed this problem earlier, but since I''ve narrowed the scope, I >> thought I''d >> start a new thread. >> >> I''m trying to create scaffold code for a simple table. I''m working off of a >> local mysql server on a development box that I use every day, so I''m very >> familiar with the environment. >> >> When I run: >> >> > ruby script/generate scaffold Category >> >> The script fails with this error message: >> error Before updating scaffolding from new DB schema, try >> creating a tab >> le for your model (Categoty) >> >> The table is there (check, and re-checked 10 times), but what is odd, >> it doesn''t >> matter what I have my db password set to in my database.yml file... If it is >> blank, the script fails with: >> #28000Access denied for user ''mike''@''localhost'' (using password: NO) >> Which is what I would expect... but when I have my password, or >> anything else, I >> get the preceding error. >> >> So, it seems weird that the generate script isn''t failing with an error >> stating >> that my password is wrong. >> >> I''ve upgraded to 0.12.1... Please help. >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > > What table name are you trying to use? In this case, a model with the > name ''Category'' should have a table called ''categories'' in the db. > > Dave >Yes, I have a table called `categories` in my db... but as I said, it looks like the db connection isn''t really even being made (I get the same error regardless of whether I have the correct or incorrect password set for the connection). Is it possible that there''s a bug in 0.12.1??
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Mike Evans wrote:> Yes, I have a table called `categories` in my db... but as I said, it > looks like > the db connection isn''t really even being made (I get the same error > regardless > of whether I have the correct or incorrect password set for the > connection). Is it possible that there''s a bug in 0.12.1??I don''t know if it''s related, but I had to specify the path to the named pipe file in my yaml file... - -- David Morton Maia Mailguard server side anti-spam/anti-virus solution: http://www.maiamailguard.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFCaon0SIxC85HZHLMRAlZ2AJ4qD3GJPwTX/G5zvwVNMdpDN48ntACePdc5 Xq12GFw7wD9ipT25OB0GtvE=Cpkz -----END PGP SIGNATURE-----
Ok, I''d really like to follow up on this problem, as it''s had me stumped for days. While developing a new rails app, if I use any user other than root for the database connection the scaffold generation script fails with: error Before updating scaffolding from new DB schema, try creating a table for your model (Note) So, if my database.yml looks like: development: adapter: mysql database: mike_todo host: localhost username: mike password: ** Correct password ** I get an error... please note that user ''mike'' has full privileges to all db''s in the server. However, if it looks like: development: adapter: mysql database: mike_todo host: localhost username: root password: ** Correct password ** It generates the scaffold scripts just fine. This seems like a possible bug to me, but I''m still really new to rails and would love to know why the first example won''t work. Thanks, Mike Mike Evans wrote:> Quoting David Goodlad <dgoodlad-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > >> On 4/21/05, Mike Evans <mike-u4reGlrcmwqg/H9aKuUo6lBd07bTekyB@public.gmane.org> wrote: >> >>> I posed this problem earlier, but since I''ve narrowed the scope, I >>> thought I''d >>> start a new thread. >>> >>> I''m trying to create scaffold code for a simple table. I''m working >>> off of a >>> local mysql server on a development box that I use every day, so I''m >>> very >>> familiar with the environment. >>> >>> When I run: >>> >>> > ruby script/generate scaffold Category >>> >>> The script fails with this error message: >>> error Before updating scaffolding from new DB schema, try >>> creating a tab >>> le for your model (Categoty) >>> >>> The table is there (check, and re-checked 10 times), but what is odd, >>> it doesn''t >>> matter what I have my db password set to in my database.yml file... >>> If it is >>> blank, the script fails with: >>> #28000Access denied for user ''mike''@''localhost'' (using password: NO) >>> Which is what I would expect... but when I have my password, or >>> anything else, I >>> get the preceding error. >>> >>> So, it seems weird that the generate script isn''t failing with an error >>> stating >>> that my password is wrong. >>> >>> I''ve upgraded to 0.12.1... Please help. >>> _______________________________________________ >>> Rails mailing list >>> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>> http://lists.rubyonrails.org/mailman/listinfo/rails >>> >> >> What table name are you trying to use? In this case, a model with the >> name ''Category'' should have a table called ''categories'' in the db. >> >> Dave >> > > Yes, I have a table called `categories` in my db... but as I said, it > looks like > the db connection isn''t really even being made (I get the same error > regardless > of whether I have the correct or incorrect password set for the > connection). Is it possible that there''s a bug in 0.12.1?? > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
It sounds much like your mysql privileges aren''t setup right, ie user ''mike'' can''t connect from localhost. I don''t use mysql anymore, but if I remember right the host wildcard will NOT match localhost, so you essentially need two records to give access both remote and locally. Check this perhaps: http://dev.mysql.com/doc/mysql/en/privilege-system.html Jason On 5/2/05, Mike Evans <mike-FpmKrjSK9lFgyGvZe3TC8g@public.gmane.org> wrote:> Ok, I''d really like to follow up on this problem, as it''s had me stumped > for days. While developing a new rails app, if I use any user other than > root for the database connection the scaffold generation script fails with: > error Before updating scaffolding from new DB schema, try creating a > table for your model (Note) > > So, if my database.yml looks like: > development: > adapter: mysql > database: mike_todo > host: localhost > username: mike > password: ** Correct password ** > > I get an error... please note that user ''mike'' has full privileges to > all db''s in the server. However, if it looks like: > development: > adapter: mysql > database: mike_todo > host: localhost > username: root > password: ** Correct password ** > > It generates the scaffold scripts just fine. This seems like a possible > bug to me, but I''m still really new to rails and would love to know why > the first example won''t work. > > Thanks, > Mike > > > Mike Evans wrote: > > > Quoting David Goodlad <dgoodlad-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > >> On 4/21/05, Mike Evans <mike-u4reGlrcmwqg/H9aKuUo6lBd07bTekyB@public.gmane.org> wrote: > >> > >>> I posed this problem earlier, but since I''ve narrowed the scope, I > >>> thought I''d > >>> start a new thread. > >>> > >>> I''m trying to create scaffold code for a simple table. I''m working > >>> off of a > >>> local mysql server on a development box that I use every day, so I''m > >>> very > >>> familiar with the environment. > >>> > >>> When I run: > >>> > >>> > ruby script/generate scaffold Category > >>> > >>> The script fails with this error message: > >>> error Before updating scaffolding from new DB schema, try > >>> creating a tab > >>> le for your model (Categoty) > >>> > >>> The table is there (check, and re-checked 10 times), but what is odd, > >>> it doesn''t > >>> matter what I have my db password set to in my database.yml file... > >>> If it is > >>> blank, the script fails with: > >>> #28000Access denied for user ''mike''@''localhost'' (using password: NO) > >>> Which is what I would expect... but when I have my password, or > >>> anything else, I > >>> get the preceding error. > >>> > >>> So, it seems weird that the generate script isn''t failing with an error > >>> stating > >>> that my password is wrong. > >>> > >>> I''ve upgraded to 0.12.1... Please help. > >>> _______________________________________________ > >>> Rails mailing list > >>> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > >>> http://lists.rubyonrails.org/mailman/listinfo/rails > >>> > >> > >> What table name are you trying to use? In this case, a model with the > >> name ''Category'' should have a table called ''categories'' in the db. > >> > >> Dave > >> > > > > Yes, I have a table called `categories` in my db... but as I said, it > > looks like > > the db connection isn''t really even being made (I get the same error > > regardless > > of whether I have the correct or incorrect password set for the > > connection). Is it possible that there''s a bug in 0.12.1?? > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >