Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

160
Visualizações
Create Rails Schema from JSON Variable

Is it possible to How can I generate a Rails schema from a JSON variable?

I'm looking to go from a JSON variable like this:

{
"employees":[
    {"firstName":"John", "lastName":"Doe"}, 
    {"firstName":"Anna", "lastName":"Smith"},
    {"firstName":"Peter", "lastName":"Jones"}
]
}

to having a Model called Employee with 2 fiels: firstName and lastName

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You don't generate schemas dynamically in a relational database. Even if its possible to monkey around and parse the JSON and use it to create SQL statements like:

CREATE TABLE 'employees' ...

Its just not an intelligent way to build web applications. It creates a ton of potential security issues and is not sane or maintainable.

It violates the entire way you should be using ActiveRecord - with migrations that build up the schema to a model that works for the problem domain.

If you want to store data in Postgres with an arbitrary schema use a JSON type column.

create_table :employees do |t|
  t.json 'data'
end

This will let you store whatever you want in employees.data.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda