Skip to main content

All Questions

Filter by
Sorted by
Tagged with
0 votes
1 answer
39 views

Rails association getting complex to understand

I am bit old but still new to Rails and in my learning orocess I have got stucked in a point where I can't figure out how can I make association between two entities. So here is the background of app....
Muhammad Waseem's user avatar
0 votes
1 answer
339 views

How to correctly apply a has_many relationship with an order by in Ruby on Rails 6

I am creating a User model in Rails 6 to mirror a model that exists in a separate project. There is a has_many relationship that is causing some problems. class User < ApplicationRecord ...
Ste Scott's user avatar
0 votes
3 answers
102 views

Rails associations doesn't save to db

I have this set up, but noting gets saved to the db when I try to save a practitioner. The tables are users, clinics and practitioners. The user should be able to create multiple clinics and each ...
kvnirvana's user avatar
0 votes
2 answers
35 views

how to use has many through with condition in rails

I have following models in rails. class User < ApplicationRecord has_many :vendors has_many :vendoritems, through: :vendors has_many :products end class Vendorcode < ApplicationRecord ...
hobbydev's user avatar
  • 1,709
0 votes
1 answer
232 views

How do I link to parent association in rails 5?

I am trying to do what this person did but with rails 5. In my app I have two controllers and three models. My two controllers are OrdersController and ListingsController. And my three models are ...
AaronG's user avatar
  • 84
0 votes
3 answers
1k views

Find and destroy dependent records

Over a period of time my Rails app has had various rewrites, and in some cases incorrect model associations. Currently my User model has_many :posts and its destroy method correctly removes all ...
Jody Heavener's user avatar
1 vote
1 answer
2k views

multiple select for hasMany association in CakePHP 3

I have two tables seller_businesses and seller_business_categories. and their association is as follows SellerBusinessesTable.php $this->hasMany('SellerBusinessCategories', [ '...
Gaurav's user avatar
  • 131
0 votes
3 answers
932 views

how to associate two models using has_many and belongs_to ruby on rails

I have generated two models tour and tourcategories in my application. Now I want to associate these two models using has_many and belongs_to. Where tour can relate with single tourcategory but ...
Jaspreet Kaur's user avatar
4 votes
1 answer
1k views

List all associations as links in active admin

Is it possible in active admin to list all of the has_many associations of my record as links? The code should look something like: column "belongs to" do |b| b.associations.map { |a| link_to(a....
azrosen92's user avatar
  • 8,987
0 votes
0 answers
385 views

missing FROM-clause entry for table rails custom model association

I need to create custom association for one of my projects. I have provided custom class name and foreign key in model but still getting the error. Here is my code: Comment Model: class Comment < ...
Akhil Latta's user avatar
2 votes
2 answers
108 views

Rails + MySQL - loading data from 3 tables with a specific format (very slow "has_many" relation)

I have this structure of tables: users id | name 1 | John 2 | Peter 3 | Claire services id | name 1 | home 2 | garden 3 | music user_services id | user_id | services_id 1 | 1 | 3 2 ...
user984621's user avatar
  • 48.3k
1 vote
3 answers
69 views

Has many through relationship in rails

I am using facebook api to fetch users from fb. I want to store the users in my model User I am using has many through relationship to store users User model relationship I have in my user model. ...
Ashish Singh's user avatar
0 votes
0 answers
317 views

find doesn't return associated model data cakePHP

models Question and Answer class Question extends AppModel { public $name = "Question"; public $useTable = "questions"; public $primaryKey = 'question_id'; public $hasMany = array( ...
Chanu Rats's user avatar
2 votes
3 answers
299 views

Ruby on Rails: finding a model instance from a different controller

Currently I have a has_many and belongs_to association between a Project model and a Invitation model. I have a form_form invitation in the show action of the projects controller. projects/show.html....
user3104471's user avatar
0 votes
2 answers
995 views

Creating hasMany associations in Sencha Touch 2

I'm trying to create a simple model association in Sencha Touch 2.3.1. Basically I want to have a store of coupons, arranged in categories. So every category hasMany coupons. My data is currently ...
rotemx's user avatar
  • 954
0 votes
1 answer
1k views

how to write a condition for has_many association that joins two tables?

I have a user model: class User < ActiveRecord::Base has_many :profile_label_values belongs_to :company end a profile label value model: class profileLabelValue < ActiveRecord::Base ...
user1404536's user avatar
  • 1,131
0 votes
1 answer
443 views

How does this cakephp scaffold know to display the name and not the primary key id?

I am new to cakephp and just created a basic blog using scaffolding. There are two models: User and Post. When the posts are listed, it lists the user's name, which is not the primary key. I am not ...
Philip7899's user avatar
  • 4,667
0 votes
2 answers
295 views

Not sure of my user/location association with Rails 4

I created a User and a Location models (and a Product Model too, but one problem at a time), and as I was playing with the console, I was surprised by some of the results. Models Class User < ...
Flo Rahl's user avatar
  • 1,054
0 votes
1 answer
483 views

Referencing calling instance variable when extending has_many

I have a model called Project that has many Proposals. The Project model has an attribute called winning_proposal_id Right now I have something like this to find the winning proposal as well as a ...
JoshL's user avatar
  • 1,499
2 votes
1 answer
317 views

Rails associations for a model 'owned' by many Users

I have a simple rails app that functions as a cms for a digital signage application. In this app, there will be a pool of predefined styles that I want to offer to all users. Every style includes a ...
Etienne678's user avatar
4 votes
1 answer
364 views

How do I cancel a save in before_add association callbacks?

I'm trying to cancel the save (gracefully) of a has_many element if is repeated. This is what I mean: class AdmininstratorRole < ActiveRecord::Base has_many :permissions, before_add: :...
Adrian's user avatar
  • 9,570
1 vote
1 answer
1k views

How to properly implement an association of two models/objects via the seeds.rb in Rails?

So, here is the deal: I have two models, a Player and a Team. Every team has_many players and every player belongs_to a team. The code (omitting a few unnecessary atributes from the player model): ...
sebkkom's user avatar
  • 1,436
0 votes
1 answer
2k views

Has many :through association not found

I have two models that can have tags added to them. Player Ticket and I have a Tag model which belongs to both so I have two join models tag_ticket tag_player I am getting a Could not find the ...
Joseph Le Brech's user avatar
0 votes
2 answers
113 views

How do you get the names of models that have MyObject has_many of?

Using Ruby (1.8.7) and Rails (2.3.8) doing myObject.attributes gives you a hash of attribute to value. lets say I have the scenario: class MyObject has_many :other_objects class OtherObject ...
NullVoxPopuli's user avatar
1 vote
2 answers
203 views

Problems with a has_many - belongs_to association

My data is basically Gallery(s) have many Picture(s), and Picture(s) belong_to a gallery. the pictures table has the foreign_key 'gallery_id'. Although I`ve used has_many and belongs_to associations ...
agente_secreto's user avatar
0 votes
2 answers
137 views

Ruby on Rails: has_many referential --which model objects does it own?

I am new to Rails and finished Michael Hartl's "Ruby on Rails 3 Tutorial". Although the book teaches me a lot, I find this puzzle I don't understand. To preview the puzzle, that is, I don't ...
Leo's user avatar
  • 311