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

Table Relationships #6

Open
khushroo-mistry opened this issue Apr 10, 2014 · 4 comments
Open

Table Relationships #6

khushroo-mistry opened this issue Apr 10, 2014 · 4 comments

Comments

@khushroo-mistry
Copy link

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
Copy link

@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
Copy link
Owner

@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 😄

@jelofsson
Copy link

@brandonwamboldt did you make any progress on this? thanks

@helarqjsc
Copy link

Any updates on this issue?

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

No branches or pull requests

5 participants