示例#1
0
 public static List<Post> findTaggedWith(String... tags) {
   return Post.find(
           "select distinct p from Post p join p.tags as t where t.name in (:tags) group by p.id, p.author, p.title, p.content,p.postedAt having count(t.id) = :size")
       .bind("tags", tags)
       .bind("size", tags.length)
       .fetch();
 }
示例#2
0
  @Test
  public void useTheCommentsRelation() {
    // Create a new user and save it
    User bob = new User("*****@*****.**", "secret", "Bob").save();

    // Create a new post
    Post bobPost = new Post(bob, "My first post", "Hello world").save();

    // Post a first comment
    bobPost.addComment("Jeff", "Nice post");
    bobPost.addComment("Tom", "I knew that !");

    // Count things
    assertEquals(1, User.count());
    assertEquals(1, Post.count());
    assertEquals(2, Comment.count());

    // Retrieve Bob's post
    bobPost = Post.find("byAuthor", bob).first();
    assertNotNull(bobPost);

    // Navigate to comments
    assertEquals(2, bobPost.comments.size());
    assertEquals("Jeff", bobPost.comments.get(0).author);

    // Delete the post
    bobPost.delete();

    // Check that all comments have been deleted
    assertEquals(1, User.count());
    assertEquals(0, Post.count());
    assertEquals(0, Post.count());
    assertEquals(0, Comment.count());
  }
示例#3
0
文件: Test3.java 项目: nikitozeg/TEST
  public void createPost() {
    // Create a new user and save it
    User bob = new User("*****@*****.**", "secret", "Bob").save();

    // Create a new post
    new Post(bob, "My first post", "Hello world").save();

    // Test that the post has been created
    assertEquals(1, Post.count());

    // Retrieve all posts created by Bob
    List<Post> bobPosts = Post.find("byAuthor", bob).fetch();

    // Tests
    assertEquals(1, bobPosts.size());
    Post firstPost = bobPosts.get(0);
    assertNotNull(firstPost);
    assertEquals(bob, firstPost.author);
    assertEquals("My first post", firstPost.title);
    assertEquals("Hello world", firstPost.content);
    assertNotNull(firstPost.postedAt);
  }
示例#4
0
 public static void index() {
   Post frontPost = Post.find("order by postedAt desc").first();
   List<Post> olderPosts = Post.find("order by postedAt desc").from(1).fetch(10);
   render(frontPost, olderPosts);
 }
示例#5
0
 public List<Post> news() {
   return Post.find(
           "SELECT p FROM Post p, IN(p.author.friendedBy) u WHERE u.from.id = ?1 and (U.accepted = true or u.to.id = ?1) order by p.updatedAt desc",
           this.id)
       .fetch();
 }
示例#6
0
 public static List<Post> findTaggedWith(String tag) {
   return Post.find("select distinct p from Post p join p.tags as t where t.name = ?", tag)
       .fetch();
 }
示例#7
0
 public Post next() {
   return Post.find("postedAt > ? order by postedAt asc", postedAt).first();
 }
示例#8
0
 public Post previous() {
   return Post.find("postedAt < ? order by postedAt desc", postedAt).first();
 }
示例#9
0
文件: Admin.java 项目: nateki/yabe
 public static void index() {
   String user = Security.connected();
   List<Post> posts = Post.find("author.email", user).fetch();
   render(posts);
 }