brandonwamboldt / wp-orm

[Unmaintained] Light weight ORM for WordPress
MIT License
175 stars 35 forks source link

Table Relationships #6

Open khushroo-mistry opened 10 years ago

khushroo-mistry commented 10 years ago

All the examples are related to a simple table. What about tables with relationships.

E.g. An Organisation has many employees: So when I create a Organisation object at design time I will also have a array of employee set in the organisation object. Thus composing the employee object with the organisation object.

After doing that if I save organisation can i be assured that I will have a record in the organisation table and 1 or many employees in the employee table and their foreign keys set.

Please let me know.

josegonzalez commented 10 years ago

@brandonwamboldt What about adding the following method to the Query class?

public function join($table, $one, $two, $type = 'join',  $operator = '=') {
    $this->joins[] = compact('table', 'one', 'two', 'type', 'operator');
}

The method could then be used like (real world example):

$popular_posts = Post::query()
    ->limit(3 - count($hero_posts))
    ->offset(0)
    ->join('postmeta', 'postmeta.post_id', 'post.ID')
    ->where_not_in(BasePost::get_primary_key(), $exclude)
    ->where_in(BasePost::get_primary_key(), $sticky_posts)
    ->where('postmeta.meta_key', 'turnstile_post_views_count')
    ->where_gte('post_date', date("F jS, Y", strtotime("-7 days")))
    ->sort_by('postmeta.meta_value')
    ->order('DESC')
    ->find();
brandonwamboldt commented 10 years ago

@josegonzalez That's what I'm planning on doing, I've just been gathering a bunch of examples of things I do manually that I'd want this to be flexible enough to handle :smile:

jelofsson commented 9 years ago

@brandonwamboldt did you make any progress on this? thanks

helarqjsc commented 8 years ago

Any updates on this issue?