jointable

Ruby/Rails: friend_id is not added to friendships table

你离开我真会死。 提交于 2019-12-11 09:19:22
问题 Using the Rails 4.1.4 framework. Having a problem adding a 'friend_id' to the user_friendships table below... when the program runs in rails, I am redirected to the root (as expected) and given the success message that the friendship was created. However, when I crack open the database GUI, I see that only a user_id is saved into the user_id column, and the friend_id column is always left 'nil', no matter who friends who. I've searched high and low - I know it must be something simple and it

Deleting just a join table record in Ruby on Rails

烈酒焚心 提交于 2019-12-11 07:20:10
问题 I have the following simple models: class Event < ActiveRecord::Base has_many :participations has_many :users, :through => :participations end class Participation < ActiveRecord::Base belongs_to :event belongs_to :user end class User < ActiveRecord::Base has_many :participations has_many :events, :through => :participations end What I would like to do in my view is, dependant on the current users role, delete either an event and its participation record, or just a participation record on its

Hibernate : How to Join 3 tables in one join table by Annotation?

∥☆過路亽.° 提交于 2019-12-11 05:24:21
问题 I have some roles, users and applications I want to create a mapping hibernate of this table : CREATE TABLE role_application_user ( role_identifier INTEGER not null, application_identifier INTEGER not null, user_identifier INTEGER not null, KEY FK_role_identifier (role_identifier), KEY FK_application_identifier(application_identifier), KEY FK_user_identifier (user_identifier), CONSTRAINT FK_role_identifier FOREIGN KEY (role_identifier) REFERENCES role (identifier), CONSTRAINT FK_application

Sequelize, Issue with filtering on the join model for belongsToMany associations

不羁的心 提交于 2019-12-11 01:59:19
问题 The Sequelize docs suggest that you can filter your query on join table attributes using the following params on the options object: [options.include[].through.where] I've tried to use this formulation in the code below and found that the filtering does not work. Model User and model Network are associated through the join table network-affiliations, which has additional attribute (boolean) 'confirmed'. I can't seem to write a query that returns only confirmed networks associated with a user.

One to Many Relationship with Join Table using EF Code First

只愿长相守 提交于 2019-12-10 17:16:11
问题 I have a question about how to configure the one to many relationship with a join table using Code First fluent API. I have a Company, Contact Object both share a common Address Object like below Class Address { public int AddressId ..... } Class Company { public int CompanyId ...... public virtual ICollection<Address> Address } Class Contact { public int ContactID ....... public virtual ICollection<Address> Address } My expected DB structure would be Company Table CompanyId PK NOT NULL .....

ActiveRecord::HasManyThroughAssociationPolymorphicSourceError

浪子不回头ぞ 提交于 2019-12-10 04:34:02
问题 I need a player to have many structures and the structure to belong to the player. Structure is a polymorphic relationship. class Player < ActiveRecord::Base has_many :player_structures has_many :structures, :through => player_structures end class PlayerStructures < ActiveRecord::Base belongs_to :structure, polymorphic: true belongs_to :player end class StructureA < ActiveRecord::Base has_one :player_structure, :as => :structure has_one :player, :through => :player_structure end class

Buddy List: Relational Database Table Design

三世轮回 提交于 2019-12-09 00:10:55
问题 So, the modern concept of the buddy list: Let's say we have a table called Person. Now, that Person needs to have many buddies (of which each buddy is also in the person class). The most obvious way to construct a relationship would be through a join table. i.e. buddyID person1_id person2_id 0 1 2 1 3 6 But, when a user wants to see their buddy list, the program would have to check the column 'person1_id' and 'person2_id' to find all of their buddies. Is this the appropriate way to implement

Rails: Call controller action with link_to an external link (and update a join-table)

冷暖自知 提交于 2019-12-08 12:01:59
问题 In my rails app there are posts which has links to other external pages ( @post.link gives me the link). If the current_user clicks on the link, a controller action should be triggered, namely the action viewed , which should update my database, more specifically a join-table with the information that the user has viewed the link. What I've already done so far: In my views/posts/index.html: # Looping through all the posts <%= link_to post.title, post.link, target: "_blank", controller: "posts

SQL Join query with OR Clause

China☆狼群 提交于 2019-12-08 03:47:00
问题 Need help in creating a SQL query. Little confused so asking question. Here is the situation: I have one table say EmpInfo: EmpFirstName, EmpLastName, EmpID, EmpGender, EmpDOB, EmpAddress Table2 EmpMasterID: EmpID1, EmpId2, AbsoluteEmpID EmpInfo contains sample data: EmpFirstName | EmpLastName | EmpID | EmpGender | EmpDOB | EmpAddress First1 | Last1 | 10 | M | 1/1/92 | Addr1 First2 | Last2 | 20 | F | 1/12/92 | Addr2 First3 | Last3 | 30 | F | 1/12/94 | Addr3 First4 | Last4 | 40 | M | 1/2/94 |

Counting one table of records for matching records of another table

耗尽温柔 提交于 2019-12-08 02:47:18
问题 Hey guys. This is my table of how it works: I want to be able to count the number of views (the views are unique which contains user's IP), for records that matches record in another table, for example I do a GET request and a SQL query will find matches and count the number of views that have been collected for each record, so it'll display something like this: GET query: stack Display: record_id | keyword | total_views ---------------------------------------------------- 2 | stack | 2 -----