relationship

Calculate Family Relationship from Genealogical Data

你说的曾经没有我的故事 提交于 2019-12-03 03:14:15
问题 I would like to be able to calculate the family relationship between two individuals in a family tree, given the following data schema (simplified from my actual data schema, only showing columns that directly apply to this problem): individual ---------- id gender child ---------- child_id father_id mother_id With this structure, how can one calculate the relationship between two individual id's (i.e. cousin, great grand uncle, etc.). Also, as there are actually two relationships (i.e. A-B

Sqlalchemy: secondary relationship update

折月煮酒 提交于 2019-12-03 03:12:01
I have two tables, say A and B. Both have a primary key id. They have a many-to-many relationship, SEC. SEC = Table('sec', Base.metadata, Column('a_id', Integer, ForeignKey('A.id'), primary_key=True, nullable=False), Column('b_id', Integer, ForeignKey('B.id'), primary_key=True, nullable=False) ) class A(): ... id = Column(Integer, primary_key=True) ... rels = relationship(B, secondary=SEC) class B(): ... id = Column(Integer, primary_key=True) ... Let's consider this piece of code. a = A() b1 = B() b2 = B() a.rels = [b1, b2] ... #some place later b3 = B() a.rels = [b1, b3] # errors sometimes

Add record to a has_and_belongs_to_many relationship

雨燕双飞 提交于 2019-12-03 03:10:31
问题 I have two models, users and promotions. The idea is that a promotion can have many users, and a user can have many promotions. class User < ActiveRecord::Base has_and_belongs_to_many :promotions end class Promotion < ActiveRecord::Base has_and_belongs_to_many :users end I also have a promotions_users table/model, with no id of its own. It references user_id and promotions_id class PromotionsUsers < ActiveRecord::Base end So, how do I add a user to a promotion? I've tried something like this:

Symfony2: Warning: spl_object_hash() expects parameter 1 to be object, integer given

匿名 (未验证) 提交于 2019-12-03 03:02:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a many to one relationship between the entities Project and Course because each course can have many projects so many projects could be related to the same course. These are my entities: class Project{ /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; //... other fields ... //----------------------- DATABASE RELATIONSHIP ----------------// //PROJECT-COURSE - M:1 relationship /** * @ORM\ManyToOne(targetEntity="Course", inversedBy="project") * @ORM\JoinColumn(name="course_id",

django-countries: Person() takes exactly 1 argument (0 given)

匿名 (未验证) 提交于 2019-12-03 02:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to use the django-countries application with Django for the first time but I am getting this error which has me confused. TypeError at /survey/ Person() takes exactly 1 argument (0 given) I installed django-countries 2.1.2 via pip in a virtual environment for the project. INSTALLED_APPS INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'polls', 'survey', 'django_countries', ) I am using Django 1.6.4.

Cannot add more than one relationship between nodes in neo4j

匿名 (未验证) 提交于 2019-12-03 02:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to model a social network with Neo4J. This requires a user can have multiple relationships with another user. When I try to persist these relationships, only one is stored. For example, this is the test unit I do: @Test public void testFindConnections() { Id id1 = new Id(); id1.setId("first-node"); Id id2 = new Id(); id2.setId("second-node"); idService.save(id2); id1.connectedTo(id2, "first-rel"); id1.connectedTo(id2, "second-rel"); idService.save(id1); for (Id im : idService.findAll()) { System.out.println("-" + im.getId()); if

SQLAlchemy import tables with relationships

微笑、不失礼 提交于 2019-12-03 02:23:48
I have problem with separating tables with relationships in different files. I want the tables below to be in three separate files and to import TableA in third party page, but I can not manage the load order. In most of the time I'm receiving the following error. sqlalchemy.exc. InvalidRequestError: When initializing mapper Mapper|TableA|tablea, expression 'TableB' failed to locate a name ("name 'TableB' is not defined"). If this is a class name, consider adding this relationship() to the class after both dependent classes have been defined. class TableA(Base): __tablename__ = "tablea" id =

SQLAlchemy query, join on relationship and order by count

匿名 (未验证) 提交于 2019-12-03 02:05:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have two SQLAlchemy models set up as follows: ############## # Post Model # ############## class Post(db.Model): id = db.Column(db.Integer, primary_key = True) title = db.Column(db.String(250)) content = db.Column(db.String(5000)) timestamp = db.Column(db.Integer) author_id = db.Column(db.Integer, db.ForeignKey('user.id')) likes = db.relationship('Like', backref = 'post', lazy = 'dynamic') ############### # Likes Model # ############### class Like(db.Model): id = db.Column(db.Integer, primary_key = True) voter_id = db.Column(db.Integer, db

SQLAlchemy - Self referential Many-to-many relationship with extra column

匿名 (未验证) 提交于 2019-12-03 01:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have a model representing user and I want to create a relationship between users representing that they are friends. My functional model with association table and methods to list all the friends look like this friendship = db . Table ( 'friend' , db . Column ( 'id' , db . Integer , primary_key = True ), db . Column ( 'fk_user_from' , db . Integer , db . ForeignKey ( 'user.id' ), nullable = False ), db . Column ( 'fk_user_to' , db . Integer , db . ForeignKey ( 'user.id' ), nullable = False ) ) class User ( db . Model ): ... ...

MySQL - How to insert into table that has many-to-many relationship

白昼怎懂夜的黑 提交于 2019-12-03 01:13:49
问题 I have a table of persons. Each person has a property and many persons may have a certain property. So this is a many-to-many relationship. This is the schema: CREATE TABLE persons ( person_id int(11) NOT NULL AUTO_INCREMENT, firstname varchar(30) NOT NULL, lastname varchar(30) NOT NULL, PRIMARY KEY (person_id) ); CREATE TABLE properties ( property_id int(11) NOT NULL AUTO_INCREMENT, property varchar(254) NOT NULL UNIQUE, PRIMARY KEY (property_id) ); CREATE TABLE has_property ( person_id int