Questions tagged [model-associations]

Models can associate in three main ways: one to many, one to one, and many to many.

This is tagged primarily in Ruby community. Models can associate in three main ways: one to many, one to one, and many to many.

865 questions
3
votes
4 answers

How to forbid deletion if association present

I have a many to many relationship between two models as follows: #users.rb has_many :users_to_roles has_many :roles, through: :users_to_roles #users_to_roles.rb belongs_to :user belongs_to :role #roles.rb has_many :users_to_roles has_many :users,…
gotqn
  • 42,737
  • 46
  • 157
  • 243
3
votes
2 answers

Correct usage of simple_form collection_check_boxes

I have set up 2 models as following : class Sector < ActiveRecord::Base attr_accessible :summary, :title, :sector_ids belongs_to :platform end and class Platform < ActiveRecord::Base attr_accessible :name, :url has_many :sectors end and a…
Cninroh
  • 1,796
  • 2
  • 21
  • 37
3
votes
2 answers

Rails 3 - Model association (composition) and method delegation

I have the following models and associations: class JuridicalPerson < ActiveRecord::Base end class Supplier < ActiveRecord::Base belongs_to :juridical_person delegate :company_name, :company_name=, :to => jurirical_person end The controler…
eMgz
  • 708
  • 1
  • 9
  • 20
3
votes
4 answers

Getting nested JSON output from Rails

Suppose I have a Rails app with two models Post and Comment. A post has_many comments and a comment belongs_to a post. How can I override the respond_to function in the show action in order to get a JSON response containing both the Post properties…
Andrew Lauer Barinov
  • 5,694
  • 10
  • 59
  • 83
2
votes
2 answers

Rails 3.2.1 nested form and accepts_nested_attributes_for returns: :Client(xxxxx) expected, got array(xxxxx)"

Please help me understand where I am going wrong so much so that I receive this message when I try to save my data-entry form(complex form) once I have entered all the data? I have five models as follows: class Contract < AR::Base has_many…
2
votes
1 answer

Sencha Touch 1.xx - Loading associated models from server proxy

I'm stuck trying to retrieve data from an associated model store. Allow me to give a brief overview of what I am trying to achieve. I need a List of quizes, and upon tapping on a quiz it will show a List of questions. Upon tapping on a question you…
Burnzoire
  • 51
  • 7
2
votes
0 answers

Deleting child relations with has_many_and_belongs_to in mongoid

I'm new to rails and trying to figure out associations using Mongoid. I have a Picture model that can have many colors, and one color can belong to many pictures. Queries should work in both directions (ie Picture -> Colors and Color -> Pictures),…
Ashish
  • 75
  • 1
  • 1
  • 8
2
votes
3 answers

Uninitialized constant error: Can't get this has_many :through correct

I have been around and around with this. Have seen similar questions here but it seems I have an extra complicating factor; what worked for them doesn't work for me. I have models and tables for User, Group, GroupMember. A group is owned by a user,…
2
votes
2 answers

Rails 3: how to do database call for HABTM relationship

I setup a HABTM relationship between my post model, genre model, and genres_posts model. My genre model has a name:string attribute which consists of names like 'thriller' 'western' 'horror' 'action' comedy' etc, when a user creates a post they can…
trying_hal9000
  • 4,343
  • 8
  • 43
  • 62
2
votes
1 answer

Active Admin Gem Model Association.

I just started using Active Admin Gem. I have a little bit of a problem and i was wondering if anyone had a solution. I have two models Dogs Breeders Using my application i would like to be able to find dogs breeds and then while viewing the dog…
Benjamin
  • 2,108
  • 2
  • 26
  • 46
2
votes
1 answer

Mapping UML Association class to Java Model code

I would like to know the proper way to implement UML association class in Java programming code. I have Student and Course classes. Student can attend one or more Courses, Courses can be attended by one or more Student (many-to-many relationship).…
2
votes
1 answer

Can't use attributes with sequelize.fn inside include block of findAll query

I'm trying to use sum for the data of my relational data model which mean i have billingsummary as a parent model and billingdetails as child model and both are linked with association of many to one relation. I basically did the query as const…
2
votes
2 answers

has_one :conditions being interpreted as attributes?

This association: class Business < ActiveRecord::Base has_one :map_address, :as=>:addressable, :class_name => 'Address', :conditions => {'addresses.map_address'=>true}, :dependent => :destroy end Causes this error: ruby-1.8.7-p334 :005 > n =…
pixelearth
  • 13,674
  • 10
  • 62
  • 110
2
votes
1 answer

Historical association pattern

I'm currently studying software engineering patterns and one that we've been given to study is the "historical association pattern" It refers to the historical mapping pattern given in Fowler's "Analysis patterns" book. The example we've been…
daniel
  • 118
  • 1
  • 7
2
votes
2 answers

simple_form_for error: undefined method - associated models

In my rails application I have two associated models called Magazine and Article. Magazine class Magazine < ActiveRecord::Base has_many :articles end Article class Article < ActiveRecord::Base belongs_to…
wilsonfoz
  • 867
  • 8
  • 9