I will give it a shot tomorrow.
On Mon, Aug 15, 2011 at 10:01 PM, Anas Mughal <anasmug
...@gmail.com> wrote:
> 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!
> On Sat, Jul 9, 2011 at 10:27 AM, Richtermeister <nex...@gmail.com> wrote:
>> 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:
>> > 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!
>> > On Fri, Jul 8, 2011 at 10:15 AM, Richtermeister <nex...@gmail.com>
>> wrote:
>> > > 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:
>> > > > 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 received this message because you are subscribed to the Google
>> Groups
>> > > "Propel Users" group.
>> > > To post to this group, send email to propel-users@googlegroups.com.
>> > > To unsubscribe from this group, send email to
>> > > propel-users+unsubscribe@googlegroups.com.
>> > > For more options, visit this group at
>> > >http://groups.google.com/group/propel-users?hl=en.
>> > --
>> > Anas Mughal
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Propel Users" group.
>> To post to this group, send email to propel-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> propel-users+unsubscribe@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/propel-users?hl=en.
> --
> Anas Mughal