Questions tagged as 'active-record'

1
answer

Query to return recurrence values, which have not yet been created in the database

I need to query the database where the records are not yet saved. I'll explain better: In a system that I am developing, the user can register a recurring expense, that is, that will repeat every month / days (according to the user's choice)....
asked by 12.12.2015 / 18:05
2
answers

How to best do WHERE's conditional with ActiveRecord in Rails?

I'm working with JSON in 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 would have to have a condition: # rota: pessoas.json?idade=30 def in...
asked by 06.08.2014 / 15:41
1
answer

Relationship in Rails, how to declare in Active Record?

I have a list of shops. Users are not registered in any of them at first. When he (the user) decides to register, a relationship is created between him and the establishment. It would be like Facebook's 'add friend' feature. But here's the quest...
asked by 10.03.2014 / 00:18
1
answer

Query in ActiveRecord

I have this relationship . How do I query on ActiveRecord to return data for Works , WorkZei and Wi_schools ? I've tried it like this: r = Responsible.find(1) students = r.students students.each {|s| s.scho...
asked by 04.05.2016 / 22:57
1
answer

Error connecting PHP ActiveRecord with XAMPP phpmyadmin

When trying to connect phpactiverecord to the database in phpmyadmin XAMPP by means of this code: <?php require_once 'php-activerecord/ActiveRecord.php'; $cfg = ActiveRecord\Config::instance (); $cfg->set_model_directory ( 'model' ); $...
asked by 25.02.2016 / 18:27
2
answers

List random objects

How could I generate random cars in the following model? would it be better to do this in the controller? class Pessoa < ActiveRecord::Base has_many :carros end     
asked by 26.09.2016 / 15:44
1
answer

Database 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 ActiveRecord::NoDatabaseError ? false : true end unless...
asked by 24.04.2015 / 21:00
1
answer

Relationship of products in models and bank

I'll try to be brief in my doubt. How can I model a class scheme that suits me in some things: This is all going to be done in rails 4.1, using ActiveRecord as ORM acting on MySQL. I will have a Person entity that will have a refere...
asked by 02.07.2014 / 04:47
0
answers

Understanding optional: true in one-to-many relationship in Rails 5

It has a one-to-many relationship and I can only create a child object if you use optional: true. I know it solves but I do not understand the need! In my seeds.rb I have a block of type 3.times do |n| Parent.last.children.create!( na...
asked by 05.08.2018 / 04:44
0
answers

Rails has_many through with where clause

I need help with the following problem: Is it possible that my Analysis model has_many :klasses, through: :subjects , but being filtered by attributes of the join_table AnalysisSubject? Or should my modeling be any different? class An...
asked by 07.05.2018 / 05:43