Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Declaring Joins programatically
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
anasmughal  
View profile  
 More options Jul 8 2011, 3:41 am
From: anasmughal <anasmug...@gmail.com>
Date: Fri, 8 Jul 2011 00:41:40 -0700 (PDT)
Local: Fri, Jul 8 2011 3:41 am
Subject: Declaring Joins programatically
Is there a way to declare a join programatically ?  Basically, I do
not have the the join declared in the scheme.xml file.

I want to declare the join right when I am creating the query object.

Thanks in advance!

(Sorry if this question has been addressed earlier.)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richtermeister  
View profile  
 More options Jul 8 2011, 1:15 pm
From: Richtermeister <nex...@gmail.com>
Date: Fri, 8 Jul 2011 10:15:34 -0700 (PDT)
Local: Fri, Jul 8 2011 1:15 pm
Subject: Re: Declaring Joins programatically
Easy. Since a Query is a Criteria, you can call:

$query->addJoin(Table1Peer::FIELD1, Table2Peer::FIELD2,
Criteria::RIGHT_JOIN); //or whatever

So, that always works, even for previously undeclared relationships.
What you DON'T get is the generated useXXXQuery stuff, for that you
need to declare them in the schema.

Daniel

On Jul 8, 12:41 am, anasmughal <anasmug...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Anas Mughal  
View profile  
 More options Jul 9 2011, 12:33 am
From: Anas Mughal <anasmug...@gmail.com>
Date: Fri, 8 Jul 2011 21:33:38 -0700
Local: Sat, Jul 9 2011 12:33 am
Subject: Re: [propel] Re: Declaring Joins programatically

Thanks for your help!

I tried something along those lines:

   $res = RestaurantQuery::create()->addJoin(RestaurantPeer::ID,
LocationPeer::OWNERID)->findOne();

Here is what I got:

Restaurant Object
(
    [id:protected] => 1
    [entity_id:protected] => 3
    [name:protected] => Juniors Pizza & Subs II
    [cuisinetype:protected] => Pizza
    [status:protected] => ACTIVE
    [created:protected] => 0000-00-00 00:00:00
    [updated:protected] => 2003-06-17 07:05:15
    [alreadyInSave:protected] =>
    [alreadyInValidation:protected] =>
    [validationFailures:protected] => Array
        (
        )
    [_new:protected] =>
    [_deleted:protected] =>
    [modifiedColumns:protected] => Array
        (
        )

    [virtualColumns:protected] => Array
        (
        )
)

I don't see how I could access the data for the Location table... Please
help.

Thank you very much!

--
Anas Mughal

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richtermeister  
View profile  
 More options Jul 9 2011, 1:27 pm
From: Richtermeister <nex...@gmail.com>
Date: Sat, 9 Jul 2011 10:27:02 -0700 (PDT)
Local: Sat, Jul 9 2011 1:27 pm
Subject: Re: Declaring Joins programatically
Well, you can't.. the code I showed only helps with the Join, as you
asked, not with the multi-hydration..
Normally you would call $restaurant->getLocations()->getFirst(); or
something like that, but for that you need to declare the relationship
in the schema.
Why don't you declare it? Seems like your use-case has a previously
known relationship.. Once you do that you can say:
$restaurants = RestaurantQuery::create()->joinWith('Location')-

>find();

Daniel

On Jul 8, 9:33 pm, Anas Mughal <anasmug...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Anas Mughal  
View profile  
 More options Aug 16 2011, 1:01 am
From: Anas Mughal <anasmug...@gmail.com>
Date: Mon, 15 Aug 2011 22:01:02 -0700
Local: Tues, Aug 16 2011 1:01 am
Subject: Re: [propel] Re: Declaring Joins programatically

Daniel, Thank you very much... Your suggestion has worked wonderfully for
me. I just added the relationships to my schema yesterday.

Now, I don't have to even do this:

$restaurant = RestaurantQuery::create()->*joinWith*
('Location')->findOneById(3);

After declaring the relationship in the schema, I get access to my location
object simply by:

$restaurant = RestaurantQuery::create()->findOneById(3);
$restaurant->getLocation(); // this gives me a hydrated location object.

I am wondering if I could take it a step further and filter or narrow down
by a location field.

For example, I would love to be able to get all restaurants in NY. Is there
a way to filter on the location object? Something along those lines:

RestaurantQuery::create()->*joinWith*('Location')->*filterOnLocation*("Stat e",
"NY")->find();

Is there a way to do "filterOnLocation"?

<table name="RESTAURANT" phpName="Restaurant">

   <column name="Id" phpName="Id" type="SMALLINT" size="8"
primaryKey="true"required=
"true"/>

   <column name="Name" phpName="Name" type="VARCHAR" size="100" required=
"true" defaultValue=""/>

    <foreign-key foreignTable="LOCATION" onDelete="cascade" onUpdate=
"cascade">

       <reference local="Id" foreign="OwnerId" />

    </foreign-key>

  </table>

  <table name="LOCATION" phpName="Location">

    <column name="Id" phpName="Id" type="SMALLINT" size="8" primaryKey=
"true" required="true"/>

    <column name="OwnerId" phpName="Ownerid" type="SMALLINT" size="8"required=
"true" defaultValue="0"/>

    <column name="Add1" phpName="Add1" type="VARCHAR" size="150" required=
"false"/>

    <column name="City" phpName="City" type="VARCHAR" size="30" required=
"false"/>

    <column name="State" phpName="State" type="CHAR" size="2" required=
"false"/>

    <column name="Zip" phpName="Zip" type="VARCHAR" size="5" required=
"false"/>

  </table>

Thanks in advance!

--
Anas Mughal

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Anas Mughal  
View profile  
 More options Aug 16 2011, 3:35 am
From: Anas Mughal <anasmug...@gmail.com>
Date: Tue, 16 Aug 2011 00:35:29 -0700
Local: Tues, Aug 16 2011 3:35 am
Subject: Re: [propel] Re: Declaring Joins programatically

I think I found the answer to my question in the Propel Docs:

<?php$books = BookQuery::create()
  ->filterByISBN('0140444173')
  ->useAuthorQuery() // returns a new AuthorQuery instance
->filterByFirstName('Leo') // this is an AuthorQuery method
->endUse() // merges the Authorquery in main Bookquery and returns the
BookQuery  ->orderByTitle()
  ->limit(10)
  ->find();

I will give it a shot tomorrow.

Everyday I love Propel more and more!!!

--
Anas Mughal

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Benjamin Börngen-Schmidt  
View profile  
 More options Aug 17 2011, 9:14 am
From: Benjamin Börngen-Schmidt <benja...@boerngen-schmidt.de>
Date: Wed, 17 Aug 2011 15:14:06 +0200
Local: Wed, Aug 17 2011 9:14 am
Subject: Re: [propel] Declaring Joins programatically
Hi there,

just for your information there is a very well written blog article by Francois Zaninotto about reducing the DB Queries needed. It was written for propel 1.5, but is true for 1.6

http://propel.posterous.com/reduce-your-query-count-with-propel-15

> After declaring the relationship in the schema, I get access to my location object simply by:

> $restaurant = RestaurantQuery::create()->findOneById(3);
> $restaurant->getLocation(); // this gives me a hydrated location object.

the last method call is again a new query to the DB.

But I think you could do something like

$restaurant = RestaurantQuery::create()
        ->useLocationQuery()
                ->filterByState("NY")
        ->endUse()
        ->findByPK(3);

then $restaurant->getLocation() should not execute another Query

- benjamin


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »