A google search showed me that what I want to do is not exactly Dynamic SQL, but I didn''t know what else to call this. I am trying to do the following Table1 ---------- id int (11); other_table_name varchar(50); Table1.create(:other_table_name =. "Table2") a = Table1.other_table_name b = Object.const_get(a).find(1) ... in sql. Basically, I want to store the name of a table within one db table/column, and then pull out the name of that table and run an SQL SELECT on that table. However I''m trying to do this all from within SQL. The reason for this is so I can define a completely dynamic has_many relationship that accesses another table based on what''s stored within its "other_table_name" column. Does this make sense, and is it possible? Thanks, -Shalev
makes sense but is just terrible sql. Practically any alternative to this would be better. On 8/7/05, Shalev NessAiver <snlists-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> A google search showed me that what I want to do is not exactly > Dynamic SQL, but I didn''t know what else to call this. > > I am trying to do the following > > Table1 > ---------- > id int (11); > other_table_name varchar(50); > > > Table1.create(:other_table_name =. "Table2") > > a = Table1.other_table_name > b = Object.const_get(a).find(1) > > ... in sql. > > Basically, I want to store the name of a table within one db > table/column, and then pull out the name of that table and run an SQL > SELECT on that table. However I''m trying to do this all from within > SQL. > > The reason for this is so I can define a completely dynamic has_many > relationship that accesses another table based on what''s stored within > its "other_table_name" column. > > Does this make sense, and is it possible? > > Thanks, > -Shalev > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Tobi http://www.snowdevil.ca - Snowboards that don''t suck http://typo.leetsoft.com - Open source weblog engine http://blog.leetsoft.com - Technical weblog
On Aug 7, 2005, at 5:45 PM, Shalev NessAiver wrote:> A google search showed me that what I want to do is not exactly > Dynamic SQL, but I didn''t know what else to call this. > > I am trying to do the following > > > [...] >Generally, if you want to do this without two round trips to the database, you need to use a stored procedure. Ed -- Transmogrify, LLC * <http://xmog.com/>
Shalev NessAiver wrote:>A google search showed me that what I want to do is not exactly >Dynamic SQL, but I didn''t know what else to call this. > >I am trying to do the following > >Table1 >---------- >id int (11); >other_table_name varchar(50); > > >Table1.create(:other_table_name =. "Table2") > >a = Table1.other_table_name >b = Object.const_get(a).find(1) > >... in sql. > >Basically, I want to store the name of a table within one db >table/column, and then pull out the name of that table and run an SQL >SELECT on that table. However I''m trying to do this all from within >SQL. > >The reason for this is so I can define a completely dynamic has_many >relationship that accesses another table based on what''s stored within >its "other_table_name" column. > >Even if you do this don''t you need to generate a Model for the "other_table". And then controllers and views ..... etc. etc. And will you do all that and wire every thing together dynamically too ? Nitin Borwankar>Does this make sense, and is it possible? > >Thanks, >-Shalev >_______________________________________________ >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
Heh heh. Well, I was just wondering if it was possible. I was trying to find a way to have a dynamic collection. As a more concrete example, consider a forum. Let''s say I want a post in the forum to be completely dynamic in content - it can contain a poll item, a calendar item, text, or anything else I choose. If I could do this dynamic sql thing then I could just say that a Post has_one :content_item and add on the sql to create the dynamic collection. Then, I could do things like: Post.find(1).content_item.render (And yes, I know that asking the model to render violates MVC, I can get around this but that''s not the point of the whole thing). Now that you say that it''s not a good thing to use stored procedures I''m sure there''s another/better way. I''ve just got to find it. Anyway thanks for the help, Shalev On 8/7/05, Nitin Borwankar <nitin-Qqau3XzocN954TAoqtyWWQ@public.gmane.org> wrote:> Shalev NessAiver wrote: > > >A google search showed me that what I want to do is not exactly > >Dynamic SQL, but I didn''t know what else to call this. > > > >I am trying to do the following > > > >Table1 > >---------- > >id int (11); > >other_table_name varchar(50); > > > > > >Table1.create(:other_table_name =. "Table2") > > > >a = Table1.other_table_name > >b = Object.const_get(a).find(1) > > > >... in sql. > > > >Basically, I want to store the name of a table within one db > >table/column, and then pull out the name of that table and run an SQL > >SELECT on that table. However I''m trying to do this all from within > >SQL. > > > >The reason for this is so I can define a completely dynamic has_many > >relationship that accesses another table based on what''s stored within > >its "other_table_name" column. > > > > > > Even if you do this don''t you need to generate a Model for the > "other_table". > And then controllers and views ..... etc. etc. > And will you do all that and wire every thing together dynamically too ? > > Nitin Borwankar > > >Does this make sense, and is it possible? > > > >Thanks, > >-Shalev > >_______________________________________________ > >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 > > > >
On 8/8/05, Shalev NessAiver <snlists-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: <snip>> Now that you say that it''s not a good thing to use stored procedures > I''m sure there''s another/better way. I''ve just got to find it.There''s nothing intrinsically wrong with using stored procedures - it would appear that it is fact the best solution to your (admittedly somewhat odd :) problem. Stored procedures have their place and are very useful in many circumstances, you just have to make sure you use them where appropriate. Cheers, -DF
Shavel, What about serializing (marshaling in Ruby, right?) whatever it is you want to display and storing it in a post? A post would have columns for headers i.e. metadata as well as a text or blog to store a serialized item. You could have a chunk of text, HTML, a poll, whatever. Ed -- Transmogrify, LLC * <http://xmog.com/>
Well, that would work except that a post isn''t the only place the data can be displayed. For instance, a calendar item can show up in the calendar and/or in a forum post. Think of the forum as a sort of dynamic aggregator. Content from almost anywhere in the site shows up in it for people to comment on. -Shalev On 8/7/05, Ed Watkeys <edw-tIV1OJqwIcc@public.gmane.org> wrote:> Shavel, > > What about serializing (marshaling in Ruby, right?) whatever it is > you want to display and storing it in a post? A post would have > columns for headers i.e. metadata as well as a text or blog to store > a serialized item. You could have a chunk of text, HTML, a poll, > whatever. > > Ed > > -- > Transmogrify, LLC * <http://xmog.com/> > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On Aug 7, 2005, at 10:03 PM, Shalev NessAiver wrote:> Well, that would work except that a post isn''t the only place the data > can be displayed. For instance, a calendar item can show up in the > calendar and/or in a forum post. Think of the forum as a sort of > dynamic aggregator. Content from almost anywhere in the site shows up > in it for people to comment on.Okay, how about then storing a URL to the content and then calling your web app as a web service, grabbing a representation, and then displaying it? A message post as a portlet... Ed -- Transmogrify, LLC * <http://xmog.com/>
On Sun, 2005-08-07 at 21:21 -0400, Shalev NessAiver wrote:> Heh heh. Well, I was just wondering if it was possible. I was trying > to find a way to have a dynamic collection. As a more concrete > example, consider a forum. Let''s say I want a post in the forum to be > completely dynamic in content - it can contain a poll item, a calendar > item, text, or anything else I choose. If I could do this dynamic sql > thing then I could just say that a Post has_one :content_item and add > on the sql to create the dynamic collection. Then, I could do things > like: > > Post.find(1).content_item.renderI know I am dragging up a nearly week old post, but I am catching up from an couple of trips. Why wouldn''t you include a has_one or has_many option to your other tables. You could then just check to see if there where links and render when appropriate. I know that would be a few more round trips, but it would make your life easier to ask the model the appropriate questions and deal with the output. -- Steven Critchfield <critch-wQLwMjUOumVBDgjK7y7TUQ@public.gmane.org>