many-to-many

Yii2. How to sort results by attributes in junction table?

末鹿安然 提交于 2019-12-11 06:24:22
问题 I have 3 tables: sp_pages , sp_messages and sp_messages_pages (for many-to-many relations). The sp_messages_pages table have 5 columns: id page_id message_id enabled sorting_order I want to get all messages for specific page sorting by sp_messages_pages.sorting_order using Yii2 framework. I try this code in pages class: public function getMessages() { return $this->hasMany(Messages::className(), ['id' => 'id_messages']) ->viaTable('sp_messages_pages', ['id_pages' => 'id'], function ($query) {

How to convert many-to-many entity relationship to tabular view in SQL?

可紊 提交于 2019-12-11 06:22:29
问题 Please I need help. I created a table Users (columns UserID , UserName ) and a table Project (columns ProjectID , ProjectName ) and a bridge table which shows the ProjectName and Username. Each project has more than one user, and each user can be in more than one projects. The bridge table looks like this: Is it available to make the date view like this and how? Note the Projects and the UserNames are not fixed they are dynamic they add from forms in VB.NET. 回答1: may I propose the following

Many to many relation, IN operator and possibility of improper results

心已入冬 提交于 2019-12-11 06:18:35
问题 I have a problem with creating optimal SQL query. I have private messages system where user can send single message to many of users or groups of users. Recipients are stored in single text column (don't ask me why is that I wasn't responsible for designing that) like that: [60,63,103,68] Additionaly I've added new text column where is placed group which user belongs to so I can have as a groups in database: [55,11,11,0] Now I want to get all users (receivers) and their groups. I have table

Yii2: Populating model field with value from many-to-many relation

孤人 提交于 2019-12-11 06:17:23
问题 We are trying to set-up our REST API in a way that a user can only retrieve data related to his account. Uptill now, We've only had a public API and it all worked like a charm. The public API will still get used, so we started from scratch. We have a User model, extending ActiveRecord and implementing IdentityInterface . A User will have a relation to a Customer model (Many:Many, but at least one). A User will have only one MASTER Customer. The above is saved in the database using 3 tables

ASP.net create many to many entity in C#

廉价感情. 提交于 2019-12-11 05:48:29
问题 I'm trying to create an many to many entity in asp.net C#. I have looked at the student/course example before and it is logical but something is literally wrong when I try use it in my own code. Here is the code where I'm stuck. [HttpPost] public ActionResult BuyWeapon(int weaponId) { string currentUserId = User.Identity.GetUserId(); var ctx = new DAL.ProjectStrawberryEntities(); Character character = ctx.Characters.FirstOrDefault(c => c.AccountId == currentUserId); Weapon weapon = ctx

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

FuelPHP - Ordering Many to Many Relations

与世无争的帅哥 提交于 2019-12-11 05:17:11
问题 I checked the documentation, but can't seem to find what I'm looking for. I have two tables: Pages Layouts With a table between (pages__layouts) that does the many-to-many. This is working great. However, when referencing the relationship, I always want: $p->layout[1] To be the most recent layout that also has a status of 1. Is there a conditional many-to-many in the model or do I do this in the Controller when I reference the layout for the first time? I have just been using lazy loading to

How do I establish a SQL query for this many-to-many table?

允我心安 提交于 2019-12-11 04:54:01
问题 I'm building this bartering-type function in this site using PHP/MySQL and I'm trying to create a query that responds with the following fields: owner's username, title, offerer's username, offerer's item Basically I have three tables here with the following fields: users user_id, username, email items_available item_number, owner_id (foreign key that links to user_id), title offers_open trade_id, offerers_id (fk of user_id), offerers_item(fk with item_number), receivers_id (fk from user_id)

Entity Framework Many to Many Cascade Delete Issue

非 Y 不嫁゛ 提交于 2019-12-11 04:23:35
问题 Having a strange issue working on a code first EF project. I have the following entities: public class Booking { public Guid BookingId { get; set; } public virtual List<AccountingDocumentItem> AccountingDocumentItems { get; set; } } public class AccountingDocumentItem { public Guid AccountingDocumentItemId { get; set; } public virtual List<Employee> Employees { get; set; } public virtual List<Booking> Bookings { get; set; } } public class Employee { public Guid EmployeeId { get; set; } public

Many-to-Many relationship in Zend 2 Framework

梦想的初衷 提交于 2019-12-11 04:18:34
问题 I use the Zend 2 Framework to build my web application. I implemented my database table models by this tutorial: http://framework.zend.com/manual/2.1/en/user-guide/database-and-models.html I have a many-to-many relationship between two models in my database. To get data from them I googled and found this link: http://mattmccormick.ca/2010/04/24/how-to-easily-create-models-and-table-relationships-in-zend-framework/ The problem is that all the table models extends from Zend_Db_Table_Abstract in