Questions tagged [belongs-to]

This is a master-detail relationship where one item "belongs_to" another and has a foreign key to maintain the relationship.

A master record has many detail records.
For example if we have buildings and rooms we can say that one building has_many rooms.
In a database, with tables/models, this relationship implies that rooms will have a foreign key for which building they belong to and thus the relationship will be belongs_to.

756 questions
0
votes
2 answers

Rails has_many dual relationship with other model

I'm trying to get two has_many relationships from one model to another. Specifically, I want: class Driver < Active:Record::Base has_many :reservations has_many :requested_reservations and class Reservations < Active:Record::Base belongs_to…
Josh Johnson
  • 563
  • 3
  • 11
  • 29
0
votes
2 answers

how to find an element based on two selectors?

i have a doom tree like this: ul #navigation li .active ul li.active_li li li /ul li ul li.active_li li li /ul /ul i would like to find the li with a class of active_li inside…
Patrioticcow
  • 26,422
  • 75
  • 217
  • 337
0
votes
3 answers

Rails View Undefined Method

A little background for my app. I have users that have 1 quiz and a quiz that belongs to a user. I am trying to list the quizzes that the users have taken but I get an error. NoMethodError in Users#index Showing…
daniel langer
  • 1,855
  • 2
  • 17
  • 20
0
votes
1 answer

How to get records based on info in Rails belongs_to record?

I have 2 models TourHdr and TourDetail. TourDetail belongs_to tour_hdr and TourHdr has_many tour_details. TourHdr also has an attribute called status. I want to define a method in TourDetail which will give me all TourDetails where the status…
nexar
  • 11,126
  • 3
  • 29
  • 32
-1
votes
1 answer

Is this formulation O(n) ∈ O(f) correct?

Is this formulation O(n) ∈ O(ƒ) correct? My answer is yes, because the O(n) complexity can belong to O(ƒ) if O(ƒ) > O(n) (for example if O(ƒ) = n log n). That is to say, the complexity O(n) can be part of the set described by O(ƒ) if O(ƒ) is an…
-1
votes
1 answer

How to create association with limit of items on rails

I have a model with doctor and patients with associations: Class doctor has_may :patients Class patient belongs_to :doctor I need to make limit of free payment patients and other limit for payed patients. Who can i it? For now my doctor has no…
-1
votes
1 answer

How to get posts by current tag and category simultaneously in Laravel?

I have Post, Tag and Category models. I know how to get posts by tag or posts by category. But I need to get posts by chosen tag and category simultaneously (at one time). Can somebody help? I use Laravel 8. Post model class Post extends Model { …
SlimBoy Fat
  • 71
  • 1
  • 3
-1
votes
2 answers

How to make a Employee-Company relation in Rails?

I'm trying to create a jobs board on Ruby on Rails. I'm using devise to handle accounts, and I have a Employee(device user) and Company models. In this challenge, when someone creates an account as employee, I have to check if the company domain…
-1
votes
1 answer

Laravel belongsToMany pivot with belongsTo

How can get relation Beetwen 3 tables enfants [id,nom,prenom] responsables[id,nom,prenom] relations[id,libelle] // père, mère, frère ... responsable_enfants[id,enfant_id,responsable_id,relation_id] Model Enfant.php public function…
-1
votes
1 answer

Rails through relation with has_many and belongs_to

I need to define relation between Packages and Delivers: 1 deliver can has many packages. But packages can not have delivers. Packages can just belong to Delivers. Deliver has_many packages, but package can just belongs_to delivers (or to…
-1
votes
4 answers

Laravel Eloquent Query works on controller but Blade also fails

There are two models, User id, name, surname, email, etc. Comment id, user_id, comment, etc. Comment Model public function user() { return $this->belongsTo('App\User', 'user_id', 'id'); } I can get the user's email address when I…
ersen
  • 1
  • 4
-1
votes
1 answer

How to access Rails model parent

I have a model, say Child, that belongs_to some other model Parent. For some instance child can I type child.parent in rails console to get the parent without explicitly adding child_id as a column in the Parents model?
ehouse
  • 11
-1
votes
1 answer

Rails Child id using parent id

My issue is, when I am under the camper show page Current Camper URL: campers/1 and I go to click on to view the appointment it uses the camper_id for the appointment_id which is wrong so say if the camper_id is 1 it will use the appointment_id as…
-1
votes
1 answer

Ember BelongsTo within two models issue

Good day all, Models: lesson title: DS.attr('string'), guild: DS.belongsTo('guild') guild title: DS.attr('string'), color: DS.attr('string') I create structure for full-calendar in lessons controller events: function(){ var lessons =…
iTux
  • 1,946
  • 1
  • 16
  • 20
-1
votes
2 answers

Force create a record with a belongs_to association

I have 2 models. Job and User. User has_many :jobs and Job belongs_to :user Is it at all possible for me to create a Job record with Job.create(location: "test") without defining a User? If I try this currently I am getting a Couldn't find User with…
MikeHolford
  • 1,851
  • 2
  • 21
  • 32
1 2 3
50
51