Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7539831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:29:11+00:00 2026-05-30T07:29:11+00:00

In a ruby script I am running a loop in which I am dynamically

  • 0

In a ruby script I am running a loop in which I am dynamically getting a table name from a list of tables and have to perform some sort of CRUD operation (mainly insertion) on it.
I am using Sequel Orm and have created models for the various tables.
How do I find the name of the Model for each table so that I can perform the insertion?

    tables=["table1","table2",'table3",...]
    tables.each do |t|
    #perform insertion on t
    #how to find the model name for table t?
    end

I can use a hash to store the model names for each table or can follow a pattern like converting the first character of each table to uppercase or something like that.

Is there a better way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T07:29:13+00:00Added an answer on May 30, 2026 at 7:29 am

    What you are asking is not possible in the general case without a brute force search, and even then it is ambiguous, for the simple reason that the following is valid:

    class Foo < Sequel::Model(:table1); end
    class Bar < Sequel::Model(:table1); end
    

    Basically, each model has a related dataset (usually just a simple SELECT * FROM table). However, other models can use the same or similar dataset. So going from model to table is simple, but table to model is not.

    If you’ve created your own models, the easiest way to handle what you want is to use a hash:

    ModelMap = {}
    ModelMap["table1"] = Model1
    ModelMap["table2"] = Model2
    

    Then you can just do:

    ModelMap[t]
    

    inside that each block to get the model class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a long running ruby script, in Linux, which has some interesting data
Well, the title say it all. I have a ruby script I want running
I have written a ruby script which opens up dlink admin page in firefox
My Ruby script is running a shell command and parsing the output from it.
Can I drop to an IRB prompt from a running Ruby script? I want
I've written a ruby script to do some work on a remote host. Running
I have a script running on windows box that downloads files from the net
I am trying to install ruby 1.9.2 from a ruby script using rvm which
Im running this command from ruby script: system trad install This will prompt me
say a ruby script is running ruby.rb SOMEUSERID using PHP, how can i find

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.