wp-orm
wp-orm copied to clipboard
Table Relationships
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.
@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();
@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:
@brandonwamboldt did you make any progress on this? thanks
Any updates on this issue?