使用RedBean php从两个具有一对多关系的表中搜索数据

时间:2015-06-05 11:14:04

标签: php laravel-4 orm many-to-many redbean

这是我桌子的结构;

    stu_details
    -----------
    id INT PK AI
    f_name VARCAHR(45)
    l_name VARCHAR(45)
    dob VARCHAR(45)

    subject
    ----------
    id INT PK AI
    sub_name VARCHAR(45)
    day VARCHAR(45)

    subject_has_stu_details(associative table)
    -----------------------------------------
    id INT PK AI
    subject_id INT FK (frm subject table)
    stu_details_id INT FK (frm stu_details table)

我的持久课程;

public class SubjectHasStuDetails  implements java.io.Serializable {


     private Integer id;
     private StuDetails stuDetails;
     private Subject subject;

    public SubjectHasStuDetails() {
    }
    //getters & setters......
}

public class StuDetails  implements java.io.Serializable {


     private Integer id;
     private String FName;
     private String LName;
     private String dob;
     private Set subjectHasStuDetailses = new HashSet();

    public StuDetails() {
    }
    //getters & setters......
}

public class Subject  implements java.io.Serializable {


     private Integer id;
     private String subName;
     private String day;
     private Set subjectHasStuDetailses = new HashSet();
     private Set teachers = new HashSet();

    public Subject() {
    }

    //getters & setters......
}

在javaEE中使用hibernate我可以像下面那样检索数据; (我正试图让所有与学生相关的科目)

      Session ss = util.HibernateUtil.getSessionFactory().openSession();
       String student_Name="Jhon"; 
        List<SubjectHasStuDetails> stu_sub = ss.
            createQuery("FROM SubjectHasStuDetails shs WHERE"
                    + " shs.stuDetails.FName= :nm").
            setParameter("nm", student_Name).list();
    for (SubjectHasStuDetails shs : stu_sub) {

        System.out.println("Name - " + shs.getStuDetails().getFName()
                + "  Subject - " + shs.getSubject().getSubName());
    }

这是我的redbean代码;

   $subject_table = R::findAll('subject');
    foreach ($subject_table as $subject) {
        echo $subject->id;
        foreach ($subject->sharedTable as $sub) {
            echo $sub->sub_name;
        }
    }

但是在RedBean中,我甚至没有得到正确的数据 在重新编写文档之后。任何事件都很明显。

0 个答案:

没有答案