Most voted "active-record" questions
Active Record is a Pattern design for Orms (Object-Relational Mappers). The most popular implementation is the default Ruby on Rails web framework ORM.
Learn more…55 questions
Sort by count of
-
3
votes1
answer341
viewsWhat is the best way to add ENUM fields to the Rails 4 model?
I need to reference the field numbers status of the database, which are in the format ENUM, with the names of my model. What’s the best way to do that? models/item.Rb class Item <…
-
3
votes1
answer3217
viewsHow to prevent a simple query from traversing the entire Mysql database
I have an application in Rails that uses a Mysql database with a table with millions of rows. Sometimes it happens that some part of my application does a very heavy query, locking all the rest of…
-
3
votes2
answers263
viewsRails and postgres group_by data considering time zone
How do I group records by date where the field is datetime type? But that’s considering Timezone. For example: When the user type 12/10/2014 23:30:00, it is recorded in the bank 13/10/2014 01:30:00,…
-
3
votes4
answers396
viewsSelect without id field (Ror)
I am with a very silly doubt, I am making a system with Ruby on Rails and I need to make a select where the id field does not come, the problem is that this field is always present, for example:…
-
2
votes3
answers2007
viewsSelect records from a table where the record of a related table is a specific value
I have a table of technical calls and a table of appointments. Each 'CALL' has several 'CALLS' and it is in the calls that is the field that defines the status of the call (Open, Closed, In…
mysql codeigniter select relational-model active-recordasked 10 years, 8 months ago EdnaldoNeimeg 109 -
2
votes1
answer259
viewsJoin with Codeigniter Active Record
I made a query that is running ok and I am passing to the Active Record of Codeigniter but it is not working because of a Join that is a bit out with conventional, does anyone have any idea what…
-
2
votes2
answers1631
viewsCheck if data already exists in codeigniter bank
I’m starting with codeigniter using active record to make the conversation with the bank, and wanted to know how to know if an email already exists in db, would have to list all email and create a…
-
2
votes2
answers10059
viewsRead or write attempt in protected memory
I have an application in C# connecting to the database Oracle. For this the application makes use of the Nhibernate (a very old version) and Castle Activerecord. This always worked, however, now…
-
2
votes1
answer689
viewsQuery using "select" and "joins" with activerecord in Rails 4
I need to make a report and I have the following query: Deducao.joins(:prestador) .select('pessoas.razao_social, pessoas.qtd_min_mensal, count(deducoes.id)') .group('deducoes.prestador_id')…
-
2
votes1
answer54
viewsSearch for random objects using conditions
I want to seek for example 10 random people of the same party I did as follows, but this selecting people from all parties, what can be done? = D class Pessoa < ActiveRecord::Base class <<…
-
2
votes1
answer66
viewsHow to find the number of records of a model?
I created a scaffold called a book and I wanted to create a method to count how many book entries there are in my database and use that result in the controller of another scaffold, called the…
-
2
votes1
answer101
viewsHow to change an attribute in the bank via a button
I’m creating a small college project in Ruby on Rails and I came across a problem: I have a table called Person and another call Tools. People have many tools and every tool and owned by one person.…
-
2
votes1
answer120
viewsRails 4 Error each_with_index when using activerecord-import
I’m trying to import an app into Rails 4 using Gem activerecord-import. When I try to execute the command: Detail.import( columns, values, :validate => false ,:timestamps => false ) I get a…
-
2
votes1
answer138
viewsHow to avoid large SELECT memory stocking in Rails?
In the routine I’m developing, I do a simple SELECT in the bank, only in a table: Model.select("id").where(:tipo => 2).find_each do |registro| puts registro.id end But this select returns around…
-
1
votes1
answer520
viewsModel validation with Scope on Ruby on Rails
Suppose the models: class A < ActiveRecord::Base has_many :bs end class B < ActiveRecord::Base belongs_to :a has_many :cs end class C < ActiveRecord::Base belongs_to :b end If I want an…
-
1
votes1
answer146
viewsactiverecord is not saving the relationship
I have a relationship like that in Rails class ReducaoZ < ActiveRecord::Base self.table_name = 'reducaoz' has_many :aliquotas, foreign_key: 'reducaoz_id', class_name: 'Aliquota', dependent:…
-
1
votes2
answers241
viewsActive Record Rails 4
If I have a model Evaluation and I do avaliacaoes = Avaliacao.all and then avaliacoes.where("score = ?", 3). In the first command Rails searches all the ratings, what happens in the second command?…
-
1
votes3
answers169
viewsConditional relationships
I need your help I have following model: class User < Ac... enum user_type: [:normal, :admin] end And I also have the model "Department": class Department < A.... end What I need to do is make…
-
1
votes1
answer73
viewsAdd method to Activerecord::Base
I created a method in the Activerecord::Base and it uses another method to be defined in the model, I need to validate if the model method is defined before executing what I need, but it says it’s…
-
1
votes2
answers1520
viewsHow to model with inheritance a structure of People?
Hi, I’m having a hard time doing my Pessoa modeling. Theoretically it seems a very simple thing, but I can’t find a way to follow, say, "good programming practices". My problem is this: In my system…
-
1
votes1
answer165
viewsJava + Active Directory - Single Sign On
I was asked to do SSO for a web application in Java. The idea is that through computer information, the application check in the AD and according to the OR user, he has access to certain modules of…
-
1
votes1
answer558
viewsWhat is the difference between Activerecord and Repository?
I’m reading a POO book in PHP that calls PHP Object Oriented Programming [Pablo Dall'Oglio] and I was a little confused with these two Patterns design, especially when it makes use of Repository…
pattern-design software-engineering active-record repositoryasked 7 years, 8 months ago Matheus Vassoler 13 -
1
votes0
answers144
viewsRelationship Activerecord PHP
I have two tables, requests and half-payment on the table pedidos have the Foreign key meio_pagamento_id, how I define their relationship through activerecord php? I tried to: Class Meiopagamento…
-
1
votes1
answer664
viewsQuery to return recurrence values, which have not yet been created in the database
I need to make a query in the database where the records are not yet saved. I will explain better: In a system that I am developing, the user can register a recurring expense, that is, it will be…
-
1
votes1
answer188
viewsIs it mandatory to use belongs_to in Activerecord?
It is mandatory that in order to have an association between two models, I have belongs_to and has_one? Or it is possible to use only has_one/has_many between the two models, when not necessarily…
-
1
votes1
answer42
viewsCan I use activerecord for basic queries? No mapping?
I do automated testing of a large system, need to validate many tables in different databases. I’m thinking of using Active Record, but all the examples I’ve seen in research show that the tables to…
-
1
votes1
answer110
viewsShould I use foreign_key in both has_many and belongs_to?
I have two models. Office and Employee. Employee has office_id as foreign key. So, which is correct? class Office < ActiveRecord::Base has_many :employees, foreign_key: 'office_id' end class…
-
1
votes1
answer69
viewspull data from a third table in a single relation
Hi! I have 3 tables. studies, species and origins, where : estudoanimais belongs_to especie estudoanimais has_many_procedencias especie has_many estudoanimais procedencia belongs_to estudoanimal The…
-
1
votes1
answer214
viewsDifferent Model type objects mapped from a single table
It is possible to map from a single table of the database different objects of type Model with Activerecord in a Ruby on Rails project? Suppose I have in the database a table with the name customers…
-
1
votes1
answer170
viewsError running Trigger mysql
Good afternoon warriors, I’m having a problem implementing a Trigger in mysql. It turns out that I created a table called audit with the same structure of the main table of appointments, this table…
-
1
votes1
answer84
viewsRelationship Through Many-To-Many Activerecord
I have the following configuration in Rails: Company has_many :company_products has_many :products, :through => :company_products Product has_many :company_products has_many :companies, :through…
-
1
votes1
answer31
viewsHow to modify this query to get the desired result in Codeigniter?
I have an SQL that returns to me the following: 1: Hacker And Automobiles OR 2: Food and I need her to return to me: 1: Hacker And 2: Cars or Food The code I have so far is: if(!$final['termo'] ==…
-
1
votes1
answer165
viewsRuby on Rails - Relation pagination with active record and Kaminari
I’m studying Ruby On Rails and as a learning goal I made an API with the basic features of Instagram. I’m having a hard time paging the results of my following list, I also wanted to display only…
-
1
votes1
answer24
viewsI have this error in form_for Undefined method equipment_index_path
I’m trying to make a form_for to register an equipment, but whenever it goes to the view to create the equipment get error. Model of Equipment: class Equipment < ApplicationRecord validates…
-
0
votes1
answer665
viewsRelationship in Rails, how to declare in Active Record?
I have a list of commercial establishments. Users, at first, are not registered in any of them. When he (the user) decides to register, a relationship is created between him and the establishment.…
-
0
votes2
answers146
viewsAdvanced query in Ruby On Rails (Activerecord)
I need to make a query for a report more or less like this: Produto.include(:clientes).where('count(produto.id) < cliente.quantidade') In sql would be more or less like this: SELECT C.NOME,…
-
0
votes1
answer112
viewsRelationship of products in models and bank
I’ll try to be brief in my doubt. How can I model a class scheme that gives me some questions: This I will do in Rails 4.1, using Activerecord as ORM acting in Mysql. I’ll have an entity Person…
mysql ruby-on-rails modeling active-record abstractionasked 10 years, 4 months ago Bruno Casali 566 -
0
votes2
answers443
viewsHow to Best Do Conditional WHERE’s with Activerecord on Rails?
I’m working with JSON on Rails. Imagine the route: # rota: pessoas.json def index @pessoas = Pessoa.all end That’s easy! But if I want to add an optional search by age I would have to have a…
-
0
votes1
answer115
viewsDatabase configuration using rspec-Rails
In my spec/rails_helper.Rb I added the following code so that the database was automatically created when running rspec: def database_exists? ActiveRecord::Base.connection rescue…
-
0
votes2
answers91
viewsValidation of has_and_belongs_to_many in Ruby on Rails
I have the following models: class Pedido < ActiveRecord::Base has_and_belongs_to_many :produtos validate :has_one_or_less_produtos private def has_one_or_less_produtos errors.add(:produtos, 'Não…
-
0
votes1
answer89
viewsConsultation on the Activerecord
I have this relationship . How do I consult on ActiveRecord to return data from Works, WorkZei and Wi_schools? I tried so: r = Responsible.find(1) students = r.students students.each {|s|…
-
0
votes1
answer67
viewsPerformance problem when returning json with rabl after query with activerecord
I’m having trouble adjusting performance when returning json after a database query. I’ve tried a lot of things, and I’m not getting any faster. Someone can give me a boost with this ? This is the…
-
0
votes2
answers280
viewsList random objects
How could I generate random cars in the following model? it would be better to do this in controller? class Pessoa < ActiveRecord::Base has_many :carros end…
-
0
votes1
answer266
viewsHelp With Relationship Between 3 #Rails Tables
I would like your help in this problem below I have 3 tables: Product Purshase Supplier supplier_id product_id name class Purshase < ActiveRecord::Base belongs_to :product end class Product <…
-
0
votes1
answer626
viewsError when connecting PHP Activerecord with XAMPP phpmyadmin
When trying to connect phpactiverecord to the database in XAMPP phpmyadmin through this code: <?php require_once 'php-activerecord/ActiveRecord.php'; $cfg = ActiveRecord\Config::instance ();…
-
0
votes1
answer41
viewsMultiple classes for one student
I have a teaching application in it I have a model for Classes (Room) and another for Students (Student). In my business rule, each student can be enrolled in up to three classes. For this I simply…
-
0
votes2
answers75
viewsHow to pass an Array to the IN clause of a flat query?
I am using Activerecord to run queries in several different databases. In one of the queries, I have to do the following: publications_to_read = [1,2,3,4]…
-
0
votes1
answer124
viewsReturn the name instead of the ID in a Rails relationship
I have two related tables in Rails, pessoa and cidade. On the table pessoa have the field cidade_id. How to do, for example, p = Pessoa.find(1) and in place of p.cidade_id already return the name of…
-
0
votes1
answer18
viewsValidates uniqueness with one exception
Good morning, I am a beginner in Rails and I have the following problem: I need to do a validation on my model where the content needs to be unique except when it is '000000'. I’ve tried to use:…
-
0
votes1
answer94
viewsHow to return the complete object from an associative table?
The code below returns only the ID’s of their respective relationships, need that instead of returning user_id and role_id return the object user and role with the registration data. Take a look at…