many-to-many

populate a many-to-many table with access

大兔子大兔子 提交于 2019-12-04 14:10:39
I have two tables ( persons and projects ) which are in a many-to-many table, thus linked together by a third table persons_projects In ms access I now created a form showing data from the projects table. What I want is to have a subform showing all persons - datasets which participate in this project. In this subform it should also be possible to add (or delete) persons from this project—a drop-down seems the best choice here. How can I do this? I’m able to show all participants, but I’m not able to add them. seems like I have the “insert into view” problem again, since I need persons and

Hibernate criteria for many-to-many entity property

荒凉一梦 提交于 2019-12-04 13:42:54
@Entity class A { @ManyToMany private List<B> list; ... } @Entity class B { ... } I'd like to get list from A class using criteria (not sql query). Is it posible to do this? Projection in this case does not work. Unfortunately, The Criteria only allows selecting the root entity, and not any joined entity. It would thus be easier if your ManyToMany was bidirectional. You could the use the criteria equivalent of select b from B b inner join b.as a where a = :theA If that's not an option, I think the only way is to use a subquery, and thus code the criteria equivalent to select b from B b where b

Django, set initial data to formset with ManyToMany

一世执手 提交于 2019-12-04 13:31:27
问题 I need to set initial data to formset with ManyToMany field. Usually i'm doing like this when there is no ManyToMany field in forms of my fomset: PersonFormSet = forms.formsets.formset_factory(NickName, can_delete=True) init_data = [{'name':'Vasya pupkin','nick':'Vasya'}, {'name':'Vasyapupkin','nick':'Petya'}] nick_formset = PersonFormSet(initial=init_data) But now I need to set ManyToMany field initial data and tried something like this: NickNameFormSet = forms.formsets.formset_factory

How do I make Django ManyToMany 'through' queries more efficient?

依然范特西╮ 提交于 2019-12-04 13:09:53
问题 I'm using a ManyToManyField with a 'through' class and this results in a lot of queries when fetching a list of things. I'm wondering if there's a more efficient way. For example here are some simplified classes describing Books and their several authors, which goes through a Role class (to define roles like "Editor", "Illustrator", etc): class Person(models.Model): first_name = models.CharField(max_length=100) last_name = models.CharField(max_length=100) @property def full_name(self): return

Entity Framework Code First Left Join

夙愿已清 提交于 2019-12-04 13:04:25
I've created a simple DB in EF code first but appear to have hit a problem. What I would like to do is, query the DBContext to retrieve a custom object CheckedTag that would have all of the available tags and a boolean field of checked. Code First abstracts the Many-To-Many table and I can't seem to find the correct query. I've tried var qry = from t in Db.Tags from a in Db.Articles where(a.Id == articleId) select new CheckedTag { Id = t.Id, Name = t.Name, PermanentUrl = t.PermanentUrl, Checked = t.Id == null ? false : true }; and scoured the net for a few hours now. If the articleId were to

Many to Many SQL Query for selecting all Images Tagged with certain words

大兔子大兔子 提交于 2019-12-04 13:01:23
I have 2 Tables in Postgres: CREATE TABLE "images" ( "id" serial NOT NULL PRIMARY KEY, "title" varchar(300) NOT NULL, "relative_url" varchar(500) NOT NULL) and CREATE TABLE "tags" ( "id" serial NOT NULL PRIMARY KEY, "name" varchar(50) NOT NULL) To establish many to many relationship between images and tags I have another table as: CREATE TABLE "tags_image_relations" ( "id" serial NOT NULL PRIMARY KEY, "tag_id" integer NOT NULL REFERENCES "tags" ("id") DEFERRABLE INITIALLY DEFERRED, "image_id" integer NOT NULL REFERENCES "images" ("id") DEFERRABLE INITIALLY DEFERRED) Now I have to write a query

Hibernate: mapping many-to-many to Map

筅森魡賤 提交于 2019-12-04 12:32:35
问题 I am developing an application which deals with two following entities: Products (let's name it as X, Y, Z) and Materials (a, b, c, ...). It's known that every product has a recipe which indicates what materials are required for making this product. For example, to produce one X we need 2 a, 6 c and 4 d (X = 2a + 6c + 4d). That's how it reflects in a database tables: Products id INT name VARCHAR ... Materials id INT name VARCHAR ... Recipes product_id INT material_id INT count INT The "count"

Fluent nhibernate mapping problem: many to many self join with additional data

☆樱花仙子☆ 提交于 2019-12-04 12:29:05
I am struggling with mappings for the following sql tables |Post | |PostRelation | |------------------| |-----------------| |PostId |1--------*|ParentPostId | |---other stuff--- |1--------*|ChildPostId | | | |RelationType | Ideally Id like a property on post called relatedPosts as Dictionary <RelationType,IList<Post>> But at the minute Id just settle for a property on post with an IList<PostRelation>. I successfully used a many to many to get related posts, but this method loses the addtional data. Any suggestions?? I Finally found a solution after much research. So though I would post it in

Laravel 4.1: proper way to retrieve all morphedBy relations?

爷,独闯天下 提交于 2019-12-04 11:54:05
问题 Just migrated to 4.1 to take advantage of this powerful feature. everything seems to work correctly when retrieving individual 'morphedByXxxx' relations, however when trying to retrieve all models that a particular tag belongs to -- i get an error or no results. $tag = Tag::find(45); //Tag model name = 'awesome' //returns an Illuminate\Database\Eloquent\Collection of zero length $tag->taggable; //returns Illuminate\Database\Eloquent\Relations\MorphToMany Builder class $tag->taggable(); /

EF Code first related entities context fail

泪湿孤枕 提交于 2019-12-04 11:42:20
Dunno how to name this properly. I have two entities in m:n relationship: Member and Role. public class Role { public int Id { get; set; } public string Title { get; set; } public ICollection<Member> MembersInRole { get; set; } } public class Member { public int Id { get; set; } public string Name { get; set; } public string Password { get; set; } public string Email { get; set; } public ICollection<Role> Roles { get; set; } } I have made some seed data: http://i56.tinypic.com/2vjvj1w.png And wrote test: The problem is, that my Member entity has no roles assigned, even when I created them in