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
1 answer

Find by conditions on associated model in CakePHP 3

I have two tables orders and sub_orders. Their association is $orders->hasMany('SubOrders', [ 'foreignKey' => 'order_id' ]); Both tables have invoice_no and sub_invoice columns in orders and sub_orders respectively. I have to find records from…
Anuj TBE
  • 9,198
  • 27
  • 136
  • 285
3
votes
2 answers

Use Association or List attribute in UML Class diagram?

I have identified two classes that I want to implement in code like this: InsuranceProviders{ } Advice{ List providers; } If I wanted to represent these two classes in a UML class diagram, should the Advice class have an…
Robert
  • 93
  • 1
  • 7
3
votes
1 answer

How how to turn arules apriori output into dataframe in R

I have the following dataframe - CTVU. MMGID_5 EMAIL 2341 1@email.x 50 1@email.x 311 1@email.x 2341 2@email.x 2387 2@email.x 57 2@email.x 2329 2@email.x 2026 3@email.x 650 3@email.x 2369…
Davis
  • 466
  • 4
  • 20
3
votes
1 answer

Linking same table with two foreign keys in cakephp 3

I have a table match_schedules which stores matches between two teams. There is table teams to store team information. Columns of match_schedules are +-----+---------+---------+-------+-------+ | id | team_a | team_b | date | venue…
Anuj TBE
  • 9,198
  • 27
  • 136
  • 285
3
votes
1 answer

Rails4 Dynamic Select Dropdown

I am trying to set up some dynamic Dropdown Select Menus in a Search Form using form_tag. What I would like is similar functionality to the example found at Railcasts #88 Models: class Count < ActiveRecord::Base belongs_to :host end class Host <…
hackerkatt
  • 165
  • 11
3
votes
1 answer

Bizarre error in pry when testing associations

So I'm seeing this strange error when I try to do a fairly simple interactive test of an associations I've added. Here are the two models: class Lot < ActiveRecord::Base has_many :graves belongs_to :block end class Grave < ActiveRecord::Base …
3
votes
2 answers

How to access ':has_many :though' join table data when using to_json?

I have three models (simplified here): class Child < ActiveRecord::Base has_many :childviews, :dependent => :nullify has_many :observations, :through => :childviews end class Childview < ActiveRecord::Base belongs_to :observation …
qryss
  • 642
  • 1
  • 5
  • 9
3
votes
1 answer

Populated association fields on find route with blueprint option ON

My app has a "Categories" model. Categories can be children of other categories. So there is a "CategoriesAssociations" model. Here is the code : /* api/models/Categories.js */ module.exports = { attributes: { name: { type: "string" …
Armel Larcier
  • 15,747
  • 7
  • 68
  • 89
3
votes
1 answer

Ruby on Rails for reverse-auction type app

Need help, please! If I have: class User < ActiveRecord::Base has_many :user_shipments has_many :shipments, through: :user_shipments def posted_shipments user_shipments.where(role: 'shipper').map(&:shipment) end def…
jmanikan
  • 37
  • 2
3
votes
1 answer

Accessing the next record in the associated collection

I am new to Rails, trying to write a simple flashcard program where a user has a deck of vocabulary cards they are cycling through... The model is a very straightforward relationship between user and card where: User has_many :cards Card …
user3763074
  • 343
  • 5
  • 15
3
votes
2 answers

Save data in a cakephp hasmany and belongsto association at once

I know this question is asked here a many times but I also tried to follow the solutions provided at my best. As I am learning a cakephp some solutions seemed difficult to implement in a code. I am using cakephp 2.5. What I am trying to do is…
Iglance3
  • 105
  • 1
  • 11
3
votes
2 answers

Rails 4: how to implement a column with multiple elements

I'm creating a web application similar to LinkedIn using Ruby on Rails (rails 4), and I'm trying to add a "skills" column in the User table. Each user can have multiple skills, I want to be able to categorize users by skills. I could either have…
user3104471
  • 305
  • 1
  • 2
  • 11
3
votes
2 answers

has_one nested attributes not saving

I have two models Project and ProjectPipeline. I want to create a Project form that also has fields from the ProjectPipeline model. I have created the form successfully but when I hit save the values aren't stored on the database. project.rb class…
3
votes
5 answers

How to use inner join in CakePHP models

I have two tables that I want to INNER JOIN, I spent hours but I had no luck. I will be very please if some could help. My first table: properties id | room | price | location_id My second table is: locations id | country | province | district Note:…
Can Atuf Kansu
  • 523
  • 2
  • 7
  • 16
3
votes
1 answer

rails association - has_many vs has_and_belongs_to_many

I am having trouble with what I thought would be a basic association. I have a Game model and a Matchset model. In the Game model is a list of games. The games are only listed once on the games table but they can belong to many…
mcnollster
  • 537
  • 1
  • 4
  • 14