AttributeError: ‘ManyRelatedManager’ object has no attribute ‘add’? I do like in django website but got this error

JamesO is correct – it looks like your Category.articles field has a through relationship. Assuming that your models at least resemble the following class Article(models.Model): name = models.CharField(max_length=128) class Category(models.Model): name = models.CharField(max_length=128) articles = models.ManyToManyField(Article, through=”Membership”) class Membership(models.Model): article = models.ForeignKey(Article) category = models.ForeignKey(Category) author = models.CharField() then to add an Article to a … Read more

Laravel Eloquent ORM – Many to Many Delete Pivot Table Values left over

The detach method is used to release a relationship from the pivot table, whilst delete will delete the model record itself i.e. the record in the reviews table. My understanding is that delete won’t trigger the detach implicitly. You can use model events to trigger a cleanup of the pivot table, though, using something like: … Read more

Self-referencing many-to-many recursive relationship code first Entity Framework

By convention, Code First will take uni-directional associations as one to many. Therefore you need to use fluent API to let Code First know that you want to have a many to many self referencing association: protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Member>().HasMany(m => m.Friends).WithMany().Map(m => { m.MapLeftKey(“MemberId”); m.MapRightKey(“FriendId”); m.ToTable(“MembersFriends”); } ); }

Many-to-many relationships examples

Example scenario: students and courses at a university. A given student might be on several courses, and naturally a course will usually have many students. Example tables, simple design: CREATE TABLE `Student` ( `StudentID` INT UNSIGNED NOT NULL AUTO_INCREMENT, `FirstName` VARCHAR(25), `LastName` VARCHAR(25) NOT NULL, PRIMARY KEY (`StudentID`) ) ENGINE=INNODB CHARACTER SET utf8 COLLATE utf8_general_ci … Read more

How do I access the properties of a many-to-many “through” table from a django template?

The easiest way is just to pass the band to the template. Templates are capable of navigating the relationships between models and there is both members and membership_set queryset managers on Group. So here is how I would do it: view: def group_details(request, group_id): group = get_object_or_404(Group, pk=group_id) return render_to_response(‘group_details.html’, {‘group’: group}) template: <h2>{{ group.name … Read more

SQL JOIN many-to-many

It’s possible with this little trick (OUTER JOIN on the many-to-many table, with the constraint that the GroupID has to be 3 (for Drama) http://sqlfiddle.com/#!9/01cf3/1 SELECT elements.ID, elements.Element, groups.Genre FROM elements LEFT OUTER JOIN group_elements ON elements.ID = group_elements.ElementID AND group_elements.GroupID = 3 LEFT OUTER JOIN groups ON group_elements.GroupID = groups.ID LEFT OUTER JOIN means … Read more

Query a many-to-many relationship with linq/Entity Framework. CodeFirst

You can do this: var cat_id=1; // Change this variable for your real cat_id var query= from article in db.Articles where article.Categories.Any(c=>c.Category_ID==cat_id) select article; This way you will get the articles that satisfies the condition you want. This is the sql code that is generated by that query: SELECT [Extent1].[Id] AS [Id], [Extent1].[Title] AS [Title] … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)