FAQ Database Discussion Community


No such column for attribute in a join table

ruby-on-rails,activerecord,attributes,associations,jointable
I'm trying to create an app where a user chooses volunteers to complete their task. The way that volunteers are considered participants is through the selected boolean attribute placed on the TaskVolunteer join table. Unfortunately when I try to find the participants of a particular class I get the following...

Ruby on Rails go to a specific page when clicking “f.submit”

ruby-on-rails,ruby,forms,associations,form-submit
In my Ruby on Rails application I have the following form for booking_line view: <%= form_for @booking_line do |f| %> <%= f.hidden_field :showing_id %> <%= image_tag "thor_hammer.jpg",:size => "900x250" %> <td width="300px"> <br><%= f.label :seat_id, 'Please Select a Seat:' %> <br><%= f.collection_select :seat_id, free_seats, :id,:seats_available %><br> </td> <td width="300px"> <div...

Input new record into database using a form with the association belongs_to

ruby-on-rails,controller,associations,belongs-to,button-to
I’m relatively new to ruby on rails so bear with me. I'm trying to create an app where there are many Projects with specific Issues associated to each project. The following is my code: My Models: class Issue < ActiveRecord::Base belongs_to :project end class Project < ActiveRecord::Base has_many :issues has_and_belongs_to_many...

Ruby on rails implementing “repost” action for Post's model

ruby-on-rails,ruby,activerecord,associations
I have a Userand Post model with the association one-to-many. I tried to implement a repost action, add a link has_and_belongs_to_many through a table reposts. But I was faced with the following challenges: 1) Post to feed loaded as follows: followed_users="SELECT followed_id FROM relationships WHERE follower_id = :user "; replics_posts="SELECT...

let! in rspec association not accessing previously created let! variable

ruby,ruby-on-rails-3,associations,rspec2
I am using RSpec 2 and trying to load a few instance variables at the top of a model spec. They are associated, but the associations aren't coming through. The models are Column and Table -- this is not a problem the way we have it set up. Table has_many...

Association belongs_to vs nested attributes in the form

ruby-on-rails,ruby-on-rails-4,associations,simple-form
I have a situation like below: class User < ActiveRecord::Base belongs_to :user_group accepts_nested_attributes_for :user_group end class UserGroup < ActiveRecord::Base has_many :users end Controller: UsersController < ApplicationControler def new @user = User.new @user.build_user_group end def create @user = User.new(user_params) if @user.save # do something else # do something end end private...

What is wrong with this polymorphic association?

ruby,ruby-on-rails-4,associations,polymorphic-associations
I have class User::AuthInfo < ActiveRecord::Base self.table_name = "auth_infos" belongs_to :authenticable, polymorphic: true end and class User::Customer < ActiveRecord::Base self.table_name = "customers" has_one :auth_info, as: :authenticable end I am expecting that by doing this: User::Customer.last.auth_info the output should be a record from auth_info. But I see the query is wrong:...

Rails, using has_and_belongs_to_many with abstract Model

ruby-on-rails,ruby,associations,has-and-belongs-to-many
I have abstract model Detail that has child models like Carcass, Basis. Also i have User model. Can I use has_and_belongs_to_many association between User and Detail? Could it be inherited to child models? Or do I need to use that association between User and each model of Detal? The main...

Sequelize - Inserting multiple associated entities in transaction fails

transactions,associations,sequelize.js
I have two models: Status and StatusParameter. Status 'hasMany()' StatusParameter and StatusParameter 'belongsTo()' Status. I want to insert a Status record and then insert multiple StatusParameter entities associated to the new Status. I want to wrap all the inserts in a transaction as well. I am using Sequelize 2.0.5, so...

Creating associations with new() versus create()

ruby-on-rails,ruby-on-rails-4,associations,activemodel
I'm hoping that this question will lead to me understanding more about how to construct many-to-many relationships with foreign keys that don't have inherant "Rails magic", as I've been Googling for hours and still don't fully understand. Basically, Users can organize Events, and Events can be organized by many Users....

How to display company_name instead of company_id

ruby-on-rails,activerecord,associations
I have a model where I store my 'jobdescription', and a view 'Jobdetails' to display the job to the outside world, But I have an issue when I want to display 'company_name' from my 'Company' model on that view intead of the company_id. I tried different ways and it's still...

ActiveRecord Survey Model ActiveRecord Associations for Doctor -> Patient

ruby-on-rails,activerecord,associations
I'm trying to build a survey form so that a User can select a Survey template, and then a form will be rendered with questions specific to that template. class Survey < ActiveRecord::Base belongs_to :template belongs_to :patient has_many :questions, :through=> :template has_many :answers, :through=> :questions end class Template < ActiveRecord::Base...

CanCanCan authorize associated objects

ruby-on-rails,associations,cancan
My Routes.rb: resources :users resources :clients do resources :branches end I have this in Ability.rb. User can update only his own clients. can [:update], Client, :id => user.clients.pluck(:id) User should be also able to :create, :update, :show branches which belong to client. It might look somehting like this: can [:create,...

SQLAlchemy many to many relationships confusion

orm,sqlalchemy,associations
Consider the following model(from pythoncentral tutorials): class Department(Base): __tablename__ = 'department' id = Column(Integer, primary_key=True) name = Column(String) employees = relationship( 'Employee', secondary='department_employee_link' ) class Employee(Base): __tablename__ = 'employee' id = Column(Integer, primary_key=True) name = Column(String) hired_on = Column(DateTime, default=func.now()) departments = relationship( Department, secondary='department_employee_link' ) class DepartmentEmployeeLink(Base): __tablename__ =...

UML - association or aggregation (simple code snippets)

uml,associations,aggregation,class-diagram,diagramming
I drives me crazy how many books contradicts themselves. Class A {} class B {void UseA(A a)} //some say this is an association, no reference is held but communication is possible Class A {} class B {A a;} //some say this is aggregration, a reference is held But many say...

Retrieve associations in AngularJS & Rails using ngResource

ruby-on-rails,angularjs,ruby-on-rails-4,associations,ngresource
I have Record & Category model: class Record < ActiveRecord::Base belongs_to :category end class Category < ActiveRecord::Base has_many :records end The Category model has a name field which should be used for display. I am using ng-repeat to display the records, the 'record.category.name' causes my page to break: <tr ng-repeat="record...

FactoryGirl - can't write unknown attribute, and undefined method `name'

ruby-on-rails,ruby,testing,associations,factory-girl
I'm trying to create a photo factory that's in a many to one association with gallery. And I'm getting two errors, depending on how I specify the association between those two models. Here's the models: Photo belongs_to :gallery, class_name: "SevenGallery::Gallery" Gallery has_many :photos, class_name: "SevenGallery::Photo", foreign_key: "seven_gallery_gallery_id", dependent: :destroy And...

Rails 4: Complex Many to Many Relationships

ruby-on-rails,activerecord,database-design,model,associations
I have the following models.. Provider Patient Clinic Like an eco-system, all models should have many-to-many relationships with one another. It's very important that I am able to query data from all directions. After intensive research on Active Record associations, I find many blogs warning against has_and_belongs_to_many and using has_many...

How to properly Name an association table (One to one relationship)

sql,database,associations,one-to-one
Most of the time I come across many to many (Cross Reference) table, name like Table1Table2XRef. But what is the best way to name a one to one association table? I know I can migrate foreign keys in one or another table, but I am more concerned about the proper...

Getting the associated table content inside the json given to angular by rails

ruby-on-rails,json,angularjs,associations
I am using angular with rails,inside which I have an index.html.erb page which hits a controller action def index @listings=Listing.all end /app.js/ var app = angular.module("PetForLife", ['ngResource']); I am passing this @listings to my angular controller through the init method. Now the issue is this listing table has an association...

Reference to array of foreign keys

sql,associations,one-to-many,varray
Let's say I have a table T - its every row has a key (assume TID column). Now I have a second table A where for each row I'd like to have a list of values from TID. How could I achive this? I thought about creating VARRAY of values...

how to fetch users with countries, cities, states by using containable behavior in cakephp 2.x

php,mysql,associations,relation,cakephp-2.6
I have these models : Country,State,City,User with relations : Country hasMany State, State hasMany City, City hasMany User, State belongsTo Country, City belongsTo State, User belongsTo City, Now I want to fetch all the users with not only their cities but also countries and states. How can I do this?...

No such column when creating an alias for a model association in Rails

ruby-on-rails,activerecord,associations,has-many
I want to create a one to many association between a User and Task model. In my user model I'd like to give it the alias of owner and refer to the user's tasks as owned_tasks. class User < ActiveRecord::Base has_many :owned_tasks, class_name: "Task", as: :owner end class Task <...

How to lookup Company_id that has the current User

ruby-on-rails,ruby,model,associations
I want to create a new jobdescription with company_id from the current user, but it doesn't work, I tried different ways and it's still not working. So, I don't know how to build the query in my controller, if you can tell me where the issue is, that would be...

Rails, strict associations

ruby-on-rails,ruby,activerecord,associations
I have created my model: class Vehicle < ActiveRecord::Base belongs_to :player has_one :basis has_one :carcass has_one :weapon end How I can make this model able to save itself ONLY when it got its player, basis, carcass, weapon? What I need to ad to my validation?...

Two has_many associations to the same model

ruby-on-rails,ruby,associations
I have a blog model that has many posts and some of these posts are top posts. My intention is to have something like the following. class Blog has_many :posts has_many :top_posts, class_name: 'Post' end class Post belongs_to :blog end As you can see, posts and top posts are the...

Rails: uninitialized constant Model::RenamedAssociation when using class to specify model in relationship

ruby-on-rails,model,associations,has-and-belongs-to-many
I have 3 tables, Charges, Transactions and Charges_Transactions. I had to rename the associations on my models as there is an existing transactions method which was interfering with the association. See this article class Charge < ActiveRecord::Base has_and_belongs_to_many :payment_transactions, join_table: "charges_transactions", foreign_key: "charge_id", association_foreign_key: "transaction_id", class: 'Transaction' end class Transaction...

Active Record Associations - Which Controller

ruby-on-rails,activerecord,associations
I'm part way through the first section of the Active Record Associations Guide and got to this line: @order = @customer.orders.create(order_date: Time.now) In which controller would this appear? I assume this would be for a create action but I'm not sure if this would be in the customers controller or...

Rails: Skip validation on autosave

ruby-on-rails,validation,associations
I have model A that has another models B, C, D associated one to one. When I create the record of A, I want to create also B, C and D instances, and skip validations for theese three. Is it possible to do in some elegant way in Rails? Thanks...

Use many has_one relation on the same model

ruby-on-rails,associations
I have a model match like this: class Match < ActiveRecord::Base belongs_to :match, foreign_key: 'parent' belongs_to :match, foreign_key: 'child_left' belongs_to :match, foreign_key: 'child_right' end Many match represent a tree. I would like set the foreign key to use Match.first.child_left return me the object match and not just an integer who...

Two Association Label Elements in Simple Form

ruby-on-rails,ruby-on-rails-4,associations,simple-form
How can I add two label elements when choosing association in Simple Form on Ruby on Rails? Sample: @user.name = "Barack" and @user.last_name = "Obama" Here is my code: <%= f.association :persona, :collection => Persona.order(:name), :prompt => 'Choose a person' %> It displays only Barack but I need it to...

Ruby on Rails - Accessing Parent Attribute Though One to Many Association

ruby-on-rails,ruby,activerecord,associations,one-to-many
I'm fairly new to Ruby on Rails and am having issues using a one to many association I set up between two models. Here is the code for the two models that define the one to many association: class Location < ActiveRecord::Base has_many :reviews, -> { order 'created_at DESC' },...

Seeding fails validation for nested tables (validates_presence_of)

ruby-on-rails,ruby,validation,ruby-on-rails-4,associations
An Organization model has a 1:many association with a User model. I have the following validation in my User model file: belongs_to :organization validates_presence_of :organization_id, :unless => 'usertype==1' If usertype is 1, it means the user will have no organization associated to it. For a different usertype the presence of...

Can't access strong Params through another Model. Rails 4

ruby-on-rails,ruby,ruby-on-rails-4,nested,associations
For some reason I can't access param from another model. I use in my code has_many :through association. I use rails 4.2. Here is my code: /models/company.rb class Company < ActiveRecord::Base has_many :bonds has_many :users, :through => :bonds end /models/user.rb class User < ActiveRecord::Base has_many :bonds has_many :companies, :through =>...

Containable not working correctly with deep association

php,cakephp,model,associations
I have a Produto(Product) model that belongsTo Titulo(Title). Pedido(Order) hasMany Itens and the Itens belongsTo Produto(Product). however, after I use find(all) using the model Pedido containing Itens with Produto, the next find of Produto, the contain nor the recursive function works, here is an example: $proModel = ClassRegistry::Init('Produto'); pr($proModel->find('first', array('conditions'...

rails has_one and belongs_to error

ruby-on-rails,ruby-on-rails-4,activerecord,associations
I have a User model and an Organization model. A organization has one user and a user belongs to an organization. schema: create_table "organizations", force: true do |t| t.string "name" t.string "org_name" t.string "email" t.datetime "created_at" t.datetime "updated_at" t.integer "user_id" end class Organization < ActiveRecord::Base has_one :user end class User...

How to call model method in rails controller

ruby-on-rails,ruby,ruby-on-rails-4,associations
Hi I have to call model method in my controller and view. So for this I had done this: category.rb def self.category_list category = self.all.collect { |m| [m.name, m.id] } return category end products_controller.rb def new @product = Product.new @category = Category.category_list end and in products/new.html.erb <%= form_for @product, action:...

Build association while initializing to satisfy delegates

ruby-on-rails,activerecord,delegates,associations,activeadmin
I have this minimal example model: class Book < ActiveRecord::Base belongs_to :author delegate :name, prefix: true, to: author after_initialize { author ||= Author.new } end After posting form data my framework (yes, ActiveAdmin) does this: Book.new {author_name: 'Some Dude'} which results in author_name not being written since the after_initialize callback...

How can I get the className of my table in cakephp 3?

associations,cakephp-3.0
In my AcosTable.php I have $this->hasMany('ChildAcos', [ 'alias' => 'ChildAcos', 'className' => 'Acos', 'foreignKey' => 'parent_id' ]); I need table name(className property) in appController. In my appController I have $associations = $this->{$this->modelClass}->associations(); foreach ($associations->type('HasMany') as $item) { $options['name'] = $item->name(); //ChildAcos $options['foreignKey'] = $item->foreignKey(); //parent_id //$options['className'] = $item->?(); //Acos $hasMany[]...

Multiple many-to-many association between two models

ruby-on-rails-4,activerecord,associations
I've created a many to many relation ship like the following structure. Class User has_many :companies, :through => company_admins has_many :company_admins end Class Company has_many :company_admins has_many :users, :through => company_admins end Class CompanyAdmin belongs_to :company belongs_to :user end Here, User can be assigned as admin on many Company. Now...

“ People Who Liked this Also Liked ” Query in Mysql PHP

php,mysql,sql,associations,bayesian
Music table id | title 1 Rap God 2 Blank Space 3 Bad Blood 4 Speedom 5 Hit 'em up Like table u_id | m_id 1 1 1 2 1 4 1 5 2 3 2 4 2 5 3 1 3 5 4 1 4 2 4 5 Now...

CakePHP deep (multiple related models) validation?

associations,cakephp-2.3
I have a model structure that is: Organization belongsTo Address belongsTo CountryCode So, Organization has foreign keys: mailing_address_id and physical_address_id Address has foreign key: country_code_id In the Organization model, relationship is defined as: public $belongsTo = array( 'MailingAddress' => array('className'=>'Address', 'foreignKey'=>'mailing_address_id') , 'PhysicalAddress' => array('className'=>'Address', 'foreignKey'=>'physical_address_id') ); This appears to...

R. How to identify rules

r,associations,identity,rules
Does anyone know how to identify rules that show which treatments are typically used for which diseases. I have this data. First column - patient, second - disease, third - medicine. P1 D1 M1 P1 D2 M1 P2 D3 M2 M3 P2 D4 M4 P2 D1 M5 P2 D2 M6...

Rails 4 and referencing parent id in 'has_many' SQL

ruby-on-rails,associations,has-many
TL;DR: How do I use the ID of the respective parent object in a has_many SQL clause to find child objects? Long version: I have the following example code: class Person < AR::Base has_many :purchases, -> { "SELECT * from purchases WHERE purchase.seller_id = #{id} OR purchase.buyer_id = #{id}" }...

What is the correct Grails ORM (GORM) implementation to use?

grails,orm,model,associations,gorm
As a result of a change request I need to implement the correct ORM for my Grails application. I currently have the following simple models and associations: Agent static hasMany = [fees:Fee] Fee static belongsTo = [agent:Agent] However, now I need to implement the ability for a single Fee to...

What would be the appropriate model association?

ruby-on-rails,ruby,postgresql,ruby-on-rails-4,associations
I have an Organization and Actioncode model. When signing up for a premium account, an organization can enter an actioncode for a discount. Hence, an organization has used no or 1 actioncode, while an actioncode can be used by many organizations. Current association: Organizations migration file: t.references :actioncode, index: true,...

Rails 4 many-to-many associations nightmare

ruby-on-rails,ruby,activerecord,many-to-many,associations
I'm trying to set up a has_many :through association between three models: Trip, Location and LocationsTrip, but the associations just don't seem to be picking each other up. I set up my associations: class Trip < ActiveRecord::Base belongs_to :user has_many :locations_trips has_many :locations, :through => :locations_trips accepts_nested_attributes_for :locations_trips, :allow_destroy =>...

Why is foreign_key ignored?

ruby-on-rails,ruby,associations,models
I have 2 models with has_one and has_many associations. realm.rb class Realm < ActiveRecord::Base has_one :realm_type, foreign_key: "id" end realm_type.rb class RealmType < ActiveRecord::Base has_many :realms, foreign_key: "realm_type_id" end But when i preforming sql request Realm.find(1).realm_type in rails console, i get Realm Load (0.3ms) SELECT "realms".* FROM "realms" WHERE "realms"."id"...

Ordered Bag in UML

uml,associations,class-diagram
When a UML Class diagram association takes <orderedSet> annotation, it seems it means there is an order (yet unknown) between the elements at the end of the association. For example: A ---> <orderedSet> B means that for each a:A, its associated set of elements from B are ordered (e.g., a...

Custom filter for grid view not working (two associated models)

ruby-on-rails,ruby,ruby-on-rails-4,gridview,associations
I am using wice_grid and have two associated tables: Organization and User (with a 1:many relationship). For a grid view of all users I would like to include a column which states the name of the organization that the user belongs to (a variable in the organization model). To this...

Nested Routes - Broken Form, NoMethodError - undefined method

ruby-on-rails,ruby,associations,nested-routes
To learn Rails, I'm working on a simple calendar app. To get started, I created two scaffolds and the proper associations/routes: calendars content_items app/models/calendar.rb class Calendar < ActiveRecord::Base has_many :content_items end app/models/content_item.rb class ContentItem < ActiveRecord::Base belongs_to :calendar end routes.rb resources :calendars do resources :content_items end controllers/content_items_controller.rb def create @content_item...

Rails 4 - has_one and has_many at the same time

ruby-on-rails-4,associations
I have the following setup: class Album < ActiveRecord::Base has_many :photos end class Photo < ActiveRecord::Base belongs_to :album end What I would like to do, is defining a profile_photo and a cover_photo for each album, but I'm not sure on how to approach the design. First attempt has been to...

File association using CMD

file,cmd,associations
What are ways to associate file from cmd? For example,I want .txt file extension to associate with a typical program, through command prompt? what is the correct file association cmd command?

Displaying nested association in view in Rails 4

ruby-on-rails,associations,model-associations
I have 3 models as below: class Kick < ActiveRecord::Base has_many :offs has_many :retailers, :through => :off end class Retailer < ActiveRecord::Base has_many :offs has_many :kicks, :through => :off end class Off < ActiveRecord::Base belongs_to :kicks belongs_to :retailers end And I'm trying to display the name of the retailer in...

Rails: select model

sql,ruby-on-rails,activerecord,associations
I have a model Shop: class Shop < ActiveRecord::Base has_and_belongs_to_many :services end and a model Service: class Service < ActiveRecord::Base has_and_belongs_to_many :shops end I would like to query every shop that provides all of the following services: Reparation Advise Shipping So return all shops where services contain reparation AND advise...

Associating three models in rails

ruby-on-rails,activerecord,associations
After reading up on Active Record Associations in the Rails Guide, it's not clear to me how I can associate three models, or if that would be unwise. I want to use the same comments model for both comments on a blog and on another page. Would it make sense...

R associations rules with arules package - how to split rule formula into vector of elements?

regex,r,data.frame,associations,arules
I have a data.frame object which I obtain by converting an object of class rules into data.frame in this way: trx.cpf.rules.df <- as(trx.cpf.rules, "data.frame") (You can build the trx.cpf.rules.df object from the structure dputed here). The head of this data frame looks like this: > head(trx.cpf.rules.df) rules support confidence lift...

Review model - shared across two different other models

ruby-on-rails,associations,models
I am making an application that lets people list food items that they want to sell. They list Dishes (Dish model) and when people buy it, an Order record is created. I want people to be able to submit reviews on Dishes if they have purchased it, and also review...

Ruby on Rails 3 Multiple Associations

ruby-on-rails,ruby-on-rails-3,associations,polymorphic-associations
I have the following associations in place: class User < ActiveRecord::Base has_many :shopping_requests has_many :recommendations, :through => :shopping_requests end class ShoppingRequest < ActiveRecord::Base belongs_to :user has_many :recommendations end class Recommendation < ActiveRecord::Base belongs_to :shopping_request has_one :user, :through => :shopping_requests end Now I need to add a Compliment class. A user...

Rails retrieve associated object through

ruby-on-rails,associations,rails-models
I am looking for the correct syntax to solve the issue below. I have 3 models: User, Client, Account class Account belongs_to :client belongs_to :user end class User has_many :clients has_many :accounts, through: :clients end class Client belongs_to :user has_many :accounts I want to create a controller to retrieve all...

Whats the best way to create a self-referential association in Rails 4?

ruby-on-rails-4,associations,self-reference
In my project I am dealing with objects called Workflows. Every Workflow can have many subflows (Workflows that it calls). At the same time every workflow (Including ones with sub flows) may also act as a Superflow that is calling the sub-flows and may have many Superflows that call it...

Rails find_by - Association comparison

ruby-on-rails,activerecord,associations
I've got three models: class User < ActiveRecord::Base has_many :surveys end class Survey < ActiveRecord::Base belongs_to :user has_many :survey_sessions end class SurveySession < ActiveRecord::Base belongs_to :survey end My question: If this is possible: Survey.find_by!(id: params[:id], user: current_user) Why does this throw a SQLException at me? SurveySession.joins(:survey) .find_by!(id: params[:id], surveys: {user:...

get an array of objects via two has_many associations

ruby-on-rails,associations
I have: class Booking < ActiveRecord::Base belongs_to :job has_many :items end I want to get a list of items for a given @job. This solution works: @items = [] @job.bookings.each do |booking| booking.items.each do |item| @items << item end end But how can i do this more concisely? i.e. something...

Using rails associations when using multiple columns to establish the relationship (i.e. model_name and model_id)

ruby-on-rails,ruby,associations
I have three models, User, Institute, and File. The idea is that a user or an institute can both have many unique files. However, I am not sure how to set up the associations between them correctly. What I want to be able to happen is to have @user.files and...

Rails nested Resources not working in controller

ruby-on-rails,associations,nested-resources
I have this nested resource: resources :services do resources :users do put "assign" => "services#users#assign", as: :assign end end My form contains this: <%= button_to 'submit', service_user_assign_url(service.id, abstractor.id), method: :put %> this generates the following url, which looks fine to me: http://localhost:3000/services/1/users/2/assign and the following is in my services controller:...

How does the associations work? cakephp 3.x

associations,cakephp-3.0
i started learning new cakephp 3.x. i want to do this : $data = $this->users->find('all');//i want to get user title name debug($data->toArray());//but i use associations. It is not join. my associations code: use Cake\ORM\Table; use Cake\Validation\Validator; class UserTitlesTable extends Table { public function initialize(array $config) { $this->table('user_titles'); $this->hasMany('Users'); } }...

different ways of enforcing association relationship

ruby,uml,associations
For an association between two objects: If I have an "Office" object and a "Person" object. I would model that as an association and I've come up with the below example code as a means of enforcing it. But looking at it, there are a lot of things I would...

undefined method `users' for nil:NilClass while deleting association

ruby-on-rails,associations
I have class Clot < ActiveRecord::Base has_many :memberships has_many :users, through: :memberships end and same for users I have follow button with action def follow @clot = Clot.find(params[:id]) @clot.users << current_user redirect_to @clot end Its working fine but i want to create unfollow button i wrote = button_to 'unollow', unfollow_clot_path(@clot),...

Associative search in rails with mongodb

ruby-on-rails,associations,ruby-on-rails-4.2
i would like to perform a search in rails form with backend mongoDb, and in my model named employee data where first name, i need to search salary in another table, and i gave relation to employee data as " belongs to salary ".i tried a lot figure it out...

In Rails, how does one associated objects are up-to-date?

ruby-on-rails,validation,callback,associations
Consider: class Parent < ActiveRecord::Base has_many :blue_children has_many :red_children end class BlueChild < ActiveRecord::Base belongs_to :parent end class RedChild < ActiveRecord::Base belongs_to :parent validate :parent_cannot_have_blue_children def parent_cannot_have_blue_children unless parent.blue_children.empty? errors.add(:parent, 'has blue children') end end end For code like this: def test p = Parent.create! # Much time passes, during...

Database structure for application, offer, and accepted offer

ruby-on-rails,database,ruby-on-rails-4,activerecord,associations
I am trying to set up my database for a rails 4 website that has two types of users, one of which fills out applications and the other which makes offers on the applications - one of which, the applicant would accept. My problem is figuring out how to go...

Has Many Through relationship with accepts nested attributes

ruby-on-rails,associations,nested-attributes,has-many-through
I understand that in order to use nested attributes I need to use a has many through relationship instead of a has and belong to many so I have the following set up: class Deed < ActiveRecord::Base has_many :deeds_title_abstracts has_many :title_abstracts, through: :deeds_title_abstracts end class TitleAbstract < ActiveRecord::Base has_many :deeds_title_abstracts...

Rails multiple group_by to array

ruby-on-rails,arrays,hash,group-by,associations
Here is the kind of models I want to sort. I have one User who can have multiple Post and every of them has many Statistic. To sum up this is what I have : class User < ActiveRecord::Base has_many :posts has_many :statistics end class Post < ActiveRecord::Base belongs_to :user...

Doctrine2 QueryBuilder: How to filter out entities having zero count for a OneToMany

symfony2,doctrine2,associations,one-to-many,query-builder
In my Dymfony2 / Doctrine2 application, I have a oneToMany relation between an object and its children. I want to select all objects which have no children. I'm stuck with various errors: SingleValuedAssociationField expected, Cannot add Having sth on non result variable, etc. $queryBuilder = $this ->createQueryBuilder('object') ->leftJoin('object.children', 'children') ->andWhere('children...

What are the differences between an arrow and a closed arrow in UML to C#?

c#,uml,associations
For example I hae a class Sensor a Class Control and a Class Rooksensor. I have an open arrow from Control to Sensor and a closed arrow from Rooksensor to Sensor. Here is what the UML-diagram looks like: A little guess I did was that in the class Rooksensor its...