has-many Questions

3

Solved

I've been playing around with STI and belongs_to / has_many relationships and I'm a bit confused. I have a few questions based on a model configuration similar to: class Parental < ActiveRecor...

4

Hi following are my relations User Model public function loginlogout() { $this->HasMany("App\Models\LoginLogoutLogs"); } and this is my LoginLogoutLogs Model public function users() {...
Corkscrew asked 30/10, 2017 at 8:29

9

Solved

How can I achieve the following? I have two models (blogs and readers) and a JOIN table that will allow me to have an N:M relationship between them: class Blog < ActiveRecord::Base has_many :b...
Papillose asked 24/11, 2008 at 22:56

4

Solved

I have setup a role based access controll system with the following models: Role (as STI), UserRole (global roles) ProjectRole (project specific roles) Assignment (Polymorphic with different r...

3

Solved

I know that it will save associations when autosave: true as per https://api.rubyonrails.org/classes/ActiveRecord/AutosaveAssociation.html I know that it will save associations that are construct...
Ollie asked 9/9, 2013 at 16:44

6

Solved

I have a event model. Events can have parent events, set from a column in the model (parent_event_id). I need to be able to do has_many :event on the model, so I can just do, for example, event.chi...
Seeress asked 13/9, 2013 at 17:20

4

Solved

In my User model I could have: has_many :tasks and in my Task model: belongs_to :user Then, supposing the foreign key 'user_id' was stored in the tasks table, I could use: @user.tasks My...
Filibeg asked 22/7, 2009 at 4:14

4

Solved

I'm new to testing and rails but i'm trying to get my TDD process down properly. I was wondering if you use any sort of paradigm for testing has_many :through relationships? (or just has_many in ...
Sarcenet asked 19/10, 2010 at 23:50

8

Solved

I'm using Rails 5. I have the following model ... class Order < ApplicationRecord ... has_many :line_items, :dependent => :destroy The LineItem model has an attribute, "discount_applied....
Willable asked 25/2, 2020 at 18:15

2

Solved

Ok, i have model A that is linked to many model B, so model A have a hasMany relationship to model B and model B has a belongsTo relationship to model A. But, amongst all those B there is a partic...
Lawabiding asked 5/9, 2019 at 13:48

6

Solved

This seems fairly simple but I can't get it to turn up on Google. If I have: class City < ActiveRecord::Base has_many :photos end class Photo < ActiveRecord::Base belongs_to :city ...
Bergstrom asked 8/3, 2012 at 6:25

4

Solved

I'm not sure if my question is worded correctly. I have three models: User, Item, and UserItem. user has_many :user_items user has_many :items, through :user_items item has_many :user_items item...
Repatriate asked 8/4, 2016 at 2:36

5

Solved

What is the "rails way" to efficiently grab all rows of a parent table along with a count of the number of children each row has? I don't want to use counter_cache as I want to run these ...
Stanwood asked 28/4, 2009 at 3:48

3

This is my code for moving data from my old database: class Old < ActiveRecord::Base establish_connection :old_version self.abstract_class = true class Recipe < self set_table_name :rec...
Uredo asked 10/4, 2012 at 5:43

3

Solved

Let's say I have the following classes class SolarSystem < ActiveRecord::Base has_many :planets end class Planet < ActiveRecord::Base scope :life_supporting, where('distance_from_sun > ...
Ruthieruthless asked 24/7, 2012 at 17:53

3

Solved

I know how to work has_many :posts, dependent: :destroy. If User or something that has_many posts is destroyed, all belonging posts are also destroyed. But what happens when Post model belongs_to ...
Issuance asked 6/1, 2016 at 2:41

2

I have associations between two models defined as below: For Contact Model (in a separate file) classMethods: { associate: function (models){ Contact.belongsTo(models.User) } } For User(in a...
Selfstyled asked 13/5, 2014 at 14:30

2

Solved

I have a serializer with a has_many association and I want to order the dependent model. For some reason I get an undefined method key?' error: class API::ClientSerializer < ActiveModel::Serial...
Compromise asked 27/6, 2017 at 17:41

1

installed versions ember-cli 2.14.2 ember-data 2.14.10 A little perspective: I have a service called menu that performs store queries inside computed properties. One of these store queries is b...
Essie asked 24/8, 2017 at 19:25

2

Solved

is that possible to use direct table name in hasMany. for example public function Permissions() { return $this->hasMany('TABLE NAME'); } I have table named PERMISSION but don't have a model ...
Coats asked 11/12, 2017 at 9:22

2

I am stuck. I've been trying to figure out how to include the association changes (has_many, has_many through) on a model that has papertrail. I would like to call MyModel.versions.first.changeset ...

4

Solved

New to both Ruby and Rails but I'm book educated by now (which apparently means nothing, haha). I've got two models, Event and User joined through a table EventUser class User < ActiveRecord::...
Lawful asked 3/1, 2009 at 10:39

8

Solved

Relatively new to rails and trying to model a very simple family "tree" with a single Person model that has a name, gender, father_id and mother_id (2 parents). Below is basically what I want to do...
Burdine asked 21/11, 2008 at 1:51

3

Consider following models class User < AR has_many :resources end class Resource < AR belongs_to :user end I have a requirement where the foreign key is saved after applying some funct...
Equivocate asked 30/8, 2016 at 20:4

3

Solved

When I use has_one it works perfectly, but not on the has_many. Here you can see that the object_id is different because it ran another SQL to fetch it again. ruby-1.9.2-p290 :001 > e = Employ...
Sugary asked 4/10, 2011 at 21:21

© 2022 - 2024 — McMap. All rights reserved.