Questions tagged as 'active-record'

1
answer

Should 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 one is correct? class Office < ActiveRecord::Base has_many :employees, foreign_key: 'office_id' end class Employee < ActiveRecord::Base belongs...
asked by 04.03.2016 / 19:53
2
answers

Active Record Rails 4

If I have an Evaluation model and I make avaliacaoes = Avaliacao.all and then avaliacoes.where("score = ?", 3) . In the first command Rails fetches all evaluations, what happens in the second command? Will Rails get the core apprais...
asked by 26.08.2014 / 21:32
1
answer

activerecord is not saving the relationship

I have such a relationship in rails class ReducaoZ < ActiveRecord::Base self.table_name = 'reducaoz' has_many :aliquotas, foreign_key: 'reducaoz_id', class_name: 'Aliquota', dependent: :delete_all end class Aliquota < ActiveReco...
asked by 22.05.2014 / 16:11
1
answer

Validating a template with scope in 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 a C attribute to be unique in B's scop...
asked by 12.05.2014 / 14:27
1
answer

Relationship 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 => :company_products P...
asked by 13.09.2016 / 22:00
1
answer

Different objects of type Model mapped from a single table

Is it possible to map different Model objects with ActiveRecord in a Ruby on Rails project from a single database table? Assuming I have in the database a table named clients that will be populated by clients of the physical type and le...
asked by 16.07.2016 / 03:31
1
answer

Error executing trigger mysql

Good afternoon warriors, I'm having a problem implementing a trigger in mysql. It happens that I created a table called auditing with the same structure as the main attendance table, this audit table records all events, actions that are done in...
asked by 29.07.2016 / 19:33
1
answer

pull data from a third table in a simple relation

Hi! I have 3 tables. animal studies, species and provenances, where: estudoanimais belongs_to especie estudoanimais has_many_procedencias especie has_many estudoanimais procedencia belongs_to estudoanimal At the moment I create a provenance...
asked by 06.05.2016 / 15:58
0
answers

ActiveRecord PHP relationship

I have two tables, requests and middle_payments in the pedidos table I have the foreign key meio_pagamento_id , as I define their relationship through of activerecord php? I tried : ClassPay Payment class MeioP...
asked by 19.08.2015 / 22:11
3
answers

Conditional Relationships

I need your help I have the following template: class User < Ac... enum user_type: [:normal, :admin] end I also have the "Department" template: class Department < A.... end What I need is to do the type relationship: U...
asked by 08.04.2015 / 12:11