many-to-many

For a many to many relationship is it better to use relational database or nosql?

流过昼夜 提交于 2019-12-02 21:19:40
问题 For a many to many relationship is it better to use relational database or nosql? Let's assume you have a bunch of users. And each user can have friends that are from the same users table. So it's essentially a many to many relationship to itself. Many to many relationship in relational database will create a third table. Now I was wondering assuming this user table is huge like millions of people in there, this third table would be thus be gigantic assuming let's say each person has more

Linq2Sql Many:Many question, How would you do this?

霸气de小男生 提交于 2019-12-02 21:12:37
I know many:many isn't supported in Linq2Sql but I am working on a workaround I am working with my little SO clone and I have a table with Questions and a table with Tags and a linking table QuestionTag so I have a classic many:many relationship between Questions and Tags. To display the list of Questions on the front page I have this class I want to fill up from a Linq2Sql query public class ListQuestion { public int QuestionID { get; set; } public string Title{ get; set; } public IEnumerable<Tag> Tags { get; set; } } public IEnumerable<ListQuestion> GetQuestions() { from q in Questions .....

Hibernate: delete many-to-many association

青春壹個敷衍的年華 提交于 2019-12-02 21:08:36
I have two tables with the many-to-many association. — DB fragment: loads Id Name sessions Id Date sessionsloads LoadId SessionId — Hibernate mapping fragments: /* loads.hbm.xml */ <set name="sessions" table="sessionsloads" inverse="true"> <key column="LoadId" /> <many-to-many column="SessionId" class="Session" /> </set> … /* sessions.hbm.xml */ <set name="loads" table="sessionsloads"> <key column="SessionId" /> <many-to-many column="LoadId" class="Load" /> </set> In order to remove one entry from the association table sessionsloads , I execute this code: Session session = sessionDao.getObject

Foreign key contraints in many-to-many relationships

感情迁移 提交于 2019-12-02 21:07:38
Context We're building a blog for an intro. to databases course project. In our blog, we want to be able to set Labels on Posts . The Labels can't exist by themselves, they only do so if they are related to a Posts . This way, Labels that are not used by any Posts shouldn't stay in the database. More than one Label can belong to a single Post , and more than a single Post can use a Label . We are using both SQLite3 (locally/testing) and PostgreSQL (deployment). Implementation Here is the SQL (SQLite3 flavor) that we use to create those two tables, along with the relationship table: Posts

Rails: How to sort many-to-many relation

蹲街弑〆低调 提交于 2019-12-02 20:51:01
问题 I have a many-to-many relationship between a model User and Picture. These are linked by a join table called Picturization. If I obtain a list of users of a single picture, i.e. picture.users -> how can I ensure that the result obtained is sorted by either creation of the Picturization row (i.e. the order at which a picture was associated to a user). How would this change if I wanted to obtain this in order of modification? Thanks! Edit Maybe something like picture.users.where(:order =>

How to properly index a many-many association table?

天大地大妈咪最大 提交于 2019-12-02 20:35:38
In a typical many-many arrangement like this... Movies Actors Movies_Actors ------ ------ ------------- movie_ID actor_ID FK_movie_ID title name FK_actor_ID ... how should the association table ( 'Movies_Actors' ) be indexed for optimal read speed? I usually see this done only with the composite primary key in the association table, like so: CREATE TABLE Movies_Actors ( FK_movie_ID INTEGER, FK_actor_ID INTEGER, PRIMARY KEY (FK_movie_ID, FK_actor_ID) ) However, this seems like the index will only be useful when searching for both movie_ID and actor_ID (although I'm not certain on whether a

Unique foreign key pairs with Django

萝らか妹 提交于 2019-12-02 20:29:04
I have three models: products , users , and reviews . A review is linked to a product and a user as follows: class Review(models.Model): product = models.ForeignKey(Product) user = models.ForeignKey(User) review_text = models.TextField() creation_date = models.DateTimeField(auto_now_add=True) I'd like to allow each user to submit only one review per product. What is the recommended way to achieve this? Through the model, through verification, or something else? I'm very new to Django/Python. Thanks. Use unique_together to make sure that each user/product combination is unique: class Review

Spring and/or Hibernate: Saving many-to-many relations from one side after form submission

≡放荡痞女 提交于 2019-12-02 19:42:09
The context I have a simple association between two entities - Category and Email (NtoM). I'm trying to create web interface for browsing and managing them. I have a simple e-mail subscription edit form with list of checkboxes that represents categories, to which given e-mail belongs (I registered property editor for Set<Category> type). The problem Form displaying works well, including marking currently assigned categories (for existing e-mails). But no changes are saved to EmailsCategories table (NtoM mapping table, the one defined with @JoinTable - neither newly checked categories are added

Algorithm that searches for related items based on common tags

点点圈 提交于 2019-12-02 19:35:00
Lets take StackOverflow questions as example. Each of them has multiple tags assigned. How to build an algorithm that would find related questions based on how many common tags they have (sorted by number of common tags)? For now I can't think about anything better than just selecting all questions that have at least one common tag into an array and then looping through them all assigning number of common tags to each item, then sorting this array. Is there more clever way of doing it? Perfect solution would be a single sql query. This could be as bad as O(n^2), but it works: create table

Using EntityRepository::findBy() with Many-To-Many relations will lead to a E_NOTICE in Doctrine

自作多情 提交于 2019-12-02 18:52:43
For a Symfony2 project I had to create a relationship between a blog post and so called platforms. A platform defines a specific filter based on the domain you use to view the site. For example: If you join the site by url first-example.com, the site will only provide blog posts, which are connected to this specific platform. To do so, I created two entities Post and Platform. Afterwards I mapped them together with a Many-To-Many relationship. I'm trying to retrieve data via this Many-To-Many relationship from the builtin function findBy() in Doctrines' EntityRepository . // every one of these