Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PersistenceSpecification CheckList fails on Many-to-Many relationship #59

Open
jagregory opened this issue Jul 21, 2011 · 2 comments
Open
Labels
Milestone

Comments

@jagregory
Copy link
Collaborator

It seems that CheckList enforces ordering on the lists that it checks. I have a many-to-many relationship between Users and Roles as follows:

public UserMap()
{
  Id(x => x.Id);
  Map(x => x.UserName);
  Map(x => x.Email);
  HasManyToMany(x => x.Roles)
      .Access.CamelCaseField()
      .Inverse();
}

public RoleMap()
{
  Id(x => x.Id);
  Map(x => x.Name);
  HasManyToMany(x => x.Users)
      .Access.CamelCaseField();
}

My testing is as follows:

/* Create test Users list */
new PersistenceSpecification<Role>(session)
  .CheckProperty(u => u.Name)
  .CheckList(u => u.Users, users, (role, user) => role.AddUser(user))
  .VerifyTheMappings();

Sometimes this fails and sometimes it passes. From some debugging, it seems that it is retrieving the Users in a different order than which they were added. I imagine it because the generated Guid (using Guid.Comb) is altering the order on the database query. (I think it is because the guid is not sequential on the association table.) So basically, even though the list contains the same elements, since they are in a different order, fails the test because the source appears to compare elements by index position. So my question is, should I be enforcing an order on my queries or should CheckList not assume ordering on the list?

@icambron
Copy link
Contributor

icambron commented Sep 7, 2011

I'd modify CheckList() to be indifferent about the order. OTOH, I'm sometimes forced to add ordering in situations like this to fix paging (my database server is sometimes not even consistent about the order of results on a query against the the same data).

@leandrosa
Copy link

This issue is opened yet. Does exist some answer for this question? Cause I having this same problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants