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

Is it Possible to create two separate Identity tables for Storing Separate Login information in Asp .Net MVC 5

I am a beginner in Asp.net MVC framework. Can Asp.net MVC 5 allows to create two separate identity tables which has independent columns for storing two different user information including username and password. Store schema as follows Stores…
4
votes
2 answers

Build vs Create in has many through relationship

I wonder if anyone can help me to understand about the difference between build and create in Has Many Through (HMT) relationship? From my understanding after reading through stackoverflow and google, create is essentially build + save. However, it…
Jayzz55
  • 117
  • 2
  • 6
4
votes
1 answer

the best way to implement a friendship model in rails

I want to implement a user's friends system in my app so i found the rails space solution very nice, the idea there is to create two lines in the Friendships table : the first line for the sender invitation, and the second one for receiver relation…
medBouzid
  • 7,484
  • 10
  • 56
  • 86
4
votes
1 answer

How do i work with nested model attributes in refinerycms?

I have seen http://railscasts.com/episodes/196-nested-model-form-revised and tried the same doing with my refinery engine, but i am not able to see the nested fields in my form while adding a record from admin section and also I am not getting any…
4
votes
4 answers

Rails Rich Associations - undefined method error

I have three basic models that I am working with: class User < ActiveRecord::Base has_many :assignments end class Assignment < ActiveRecord::Base belongs_to :group belongs_to :user end class Group < ActiveRecord::Base has_many…
Dodinas
  • 6,705
  • 22
  • 76
  • 108
4
votes
1 answer

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: :avoid_repetition def avoid_repetition(permission) …
Adrian
  • 9,102
  • 4
  • 40
  • 35
4
votes
3 answers

Rails 3: validates_presence_of validation errors on default value and in associated model

I have a basic invoice setup with models: Invoice, Item, LineItems. # invoice.rb class Invoice < ActiveRecord::Base has_many :line_items, :dependent => :destroy validates_presence_of :status before_save :default_values def default_values …
leonel
  • 10,106
  • 21
  • 85
  • 129
3
votes
1 answer

CakePHP - Extended Model Associations

I've very curious about what I'm missing. Only an example will help explain but here's the sentence question first: Inventory and InventoryCategory - both have Image associations. When I view a single InventoryCategory and the related Inventory I…
radarhill
  • 33
  • 2
3
votes
2 answers

saving to multiple models from one form with rails

i have been getting into rails over the course of the last couple weeks and i've run across a problem that I can not find the answer to. i feel like this is probably something really simple but it's driving me crazy so I am hoping to get a little…
Brent
  • 1,046
  • 11
  • 13
3
votes
2 answers

how can i create three child records while updating a parent record in rails?

i have a relation like a teacher can have at max three students. I have a association like teacher has many students and student belongs to teacher. so while updating a teacher record im showing a form where student 1 followed by a text filed and…
John
  • 1,273
  • 3
  • 27
  • 61
3
votes
1 answer

Fetch associated models after fetching the Model

I have a model "Task". One Task belongs to exactly one User and one User has many Tasks. So this is a one to many relation. Now I can fetch User with their Task as follows. User.findByPk(41, {include: [Task]}); But I don't want to fetch Task while…
Amarjit Singh
  • 2,068
  • 19
  • 52
3
votes
0 answers

Rails Model Associations Mutex / Locking?

I've read quite a bit about pessimistic and optimistic locking on models in rails. However, I've yet to find any sort of information on how to implement locking on a ActiveRecord::Associations::CollectionProxy .. For instance, class Model <…
Riptyde4
  • 5,134
  • 8
  • 30
  • 57
3
votes
1 answer

How to implement 'replyingTo' and 'replies' associations on Sequelize model

I have a model in sequelize for a post. I would like that you can retrieve both the replies to a post, and what post the post acting as a reply to. In theory this just needs one foreignkey, a 'replyId' field so you have the…
user2521439
  • 1,405
  • 2
  • 13
  • 19
3
votes
2 answers

UML Diagram: Online Webstore class diagram and relation

I am working on an online web store. It's a simple web store and I have to create domain UML diagrams for the class and show multiplicities. I am kind of confused about the multiplicity that I have came up with. I don't know how to distinguish…
Temp temp2
  • 41
  • 5
3
votes
3 answers

OneToOne Double Bidirectional Association

I am newbie to UML diagrams and would like to code the following one, where there is an OneToOne double bidirectional association, with JPA annotations. Context: there are persons and teams. Each team is composed of persons and each person can…
julianfperez
  • 1,726
  • 5
  • 38
  • 69