one-to-many

One-to-many Query in MySQL

What's the best way to query one-to-many in MySQL? This is a simplified version of the database I am working on (if anything doesn't look right tell me): CREATE TABLE Tenant( tenant_id int NOT NULL, first_name varchar(20), last_name varchar(20), PRIMARY KEY (tenant_id) ); CREATE TABLE Rent( tenant_id in...

one-to-many entity referencing itself in hibernate

This seems to work, but is this the proper way for an entity to have a child set of the same entities? <hibernate-mapping> <class name="com.example.Person" table="Person"> <id name="id" column="Id" type="int"><generator class="native"/></id> <many-to-one name="childOf" class="com.example.Person" column="Child_of_Id"/...

Convert many to many to one to one (mysql)

We changed database schema and moved a relationship between users/accounts from a 1-1 to a many to many using a join table accounts_users. So we have accounts, users, accounts_users (user_id and account_id) Our data is still 1-1, and we have decided to move back. So I need sql to move back: To Migrate I used: INSERT INTO accounts_us...

Using First() with OrderBy and DynamicQuery in One-To-Many related tables

Note: I realize this question is similar to another question, however that question was asked in the context of Genom-e and remains unanswered. My question is in the context of LINQ DynamicQuery. I'm using the String extension method overload for OrderBy provided by System.Linq.Dynamic. Passing a String Literal to OrderBy works g...

Hbase and 1- Many Relation

Hi All I have one question which can be best described by the following scenario. Suppose I have three tables BaseCategory,Category and products. If i am thinking in terms of RDBMS then the relationship amoung these tables are 1- One BaseCategory has Many categories 2- One Category has Many Products. Now i am thinking to convert it ...

How to declared one-to-many if there are 2 fields for a same foreign key

I'm new to python(sqlalchemy), and I'm learning to build web site with pylons and sqlalchemy. I have a problem when I declare the relationship between models. I've tried it several hours, but failed. But I think it should be a basic question. I have two classes: User and Article, user can create articles, and modified the other people...

One to Many Linq to XML query

Hi, I have an XML string that looks like this: <Attributes> <ProductAttribute id="1"> <ProductAttributeValue> <Value>a</Value> </ProductAttributeValue> </ProductAttribute> <ProductAttribute id="2"> <ProductAttributeValue> <Value>a</Value> </ProductAttributeValue> ...

How should I handle updating data in a one-to-many relationship database schema?

Lets say I have a database similar to the following: Table: People id | name | age ---+------+----- 1 | dave | 78 Table: Likes id | userid | like ---+--------+------- 1 | 1 | apples ---+--------+------- 2 | 1 | oranges ---+--------+------- 3 | 1 | women What would be the best way to handle updating daves data? Cu...

Hibernate one to many mapping

Hi, I have two tables: <class name="Content" table="language_content" lazy="false"> <composite-id> <key-property name="contentID" column="contentID"/> <key-property name="languageID" column="languageID"/> </composite-id> <property name="Content" column="Content" /> </class> and <class name...

Rails - delete one side of a one-to-many relationship

Quick question: If I have a one-to-many relationship, such as this: class SalesPerson < ActiveRecord::Base has_many :deals end class Deal < ActiveRecord::Base belongs_to :sales_person end how can I delete a Sales Person, without negatively impacting the deals associated with them? The use-case for this would be if someone left ...

fluent-nhibernate automapping foriegn key inserts null.

I have a class called Worker public class Worker : BaseEntity { public virtual int WorkerID { get; set; } public virtual string Name { get; set; } public virtual IList<Indemnification> Indemnifications { get; set; } } public class Indemnification : BaseEntity { public virtual int IndemnificationID { get; set; } pu...

add<Key>Object vs insertNewObjectForEntityForName Core Data Relationships

Hi, Although I have a lot of experience in database development, I'm having a hard time conceptualizing linking relationships in Core Data. As I understand it, the many relationship is an NSSet attached to the one file. After reading the documentation, I've understood part of it and gotten it to work in the first import in my code bel...

One-to-many table setup

I have a table where I have to relate groups of primary keys to one another. There is no information about these groups other than that they exist. Specifically, I am storing groups of Editions of Books together, so I can know that a certain set of books are editions of each other. I currently have a setup where I have an Edition_Group_...

Grails hasMany: when child is updated, parent's version changes

I am using Grails and am quite surprised by the way hasMany relationships work. I have a typical hasMany relationship where the parent id is in the child table. When I insert a child and try to save it through the parent object, the parent object's version id gets incremented. My question is: Why should the parent's version id change whe...

In Ruby on Rails, how can a model "has_many" and "belong_to" using a different field other than primary ID?

I am trying building a simple project from scratch using Rails 3. Usually, the models are like: class Student < ActiveRecord::Base has_many :awards end class Award < ActiveRecord::Base belongs_to :student end and we use the award.id and student.id to get the corresponding records. But what if it is class Company < ActiveRecord...

Mapping list of ints in NHibernate

In NHibernate manual I have found mapping like this: <bag name="Sizes" table="SIZES" order-by="SIZE ASC"> <key column="OWNER"/> <element column="SIZE" type="Int32"/> </bag> I can't help wondering why would anyone want to do something like this? Is there something better about mapping plain integers than creating an entity corr...

Design of a Decentralized Twitter

Twitter is a popular social networking service where users can write short messages in a one-to-many fashion (you can read more about it at Wikipedia). I've been reading an interesting article by Alex Payne (former API Lead at Twitter), The Very Last Thing I’ll Write About Twitter, where he argues for a decentralized one-to-many communic...

SQL: Need help creating a one-to-many Set comparing query

The parameters are thus: I have a table called Tasks with columns ID (primary key) and label (text). I have another table called Locations with a foreign key referencing Tasks' ID and a name for a location (text). In my code I have a set of locations. UPDATED: I need a query to return all tasks that have associated locations found with...

One-to many relationship not working - Entity Framework

Hi All, I'm having a problem with creating a one-to-many(or one-to-one?) relationship in entity framework (3.5 I believe). Example tables/models: Settings: SettingsID pk int not null SettingsName varchar(250) null SettingsTypeID fk int null SettingsType: SettingsTypeID pk int not null SettingsTypeName varchar(250) ...

NHibernate eager loading one-to-many

Hi In the mapping-file I've defined a bag for Positionen. <class name="Animag.DomainModels.Models.Abrechnung, Animag.DomainModels" table="Abrechnungen" lazy="true"> <id name="ID" column="ID"> <generator class="native"/> </id> <version name="Version" column="Version"/> <many-to-one name="Kunde" column="KundeID" c...