Re: Associated Model SELECT statements
> I'm not certain, but > you might be able to specify something like: > > array('ballots.*', 'options.*') That doesn't work. I think that's for returing one field from the model that the controller is associated with. I want something very similar by to get a particular from a associated Model, not a particular field. > Also in your first question, you wrote: > $this->Ballot->Options->findAll("ballot_id=$someID"); . > > You could also write that as $this->Ballot->Options->findById($someID). > The result would be the same, but it looks a little better IMO. The result is not the same. "findById" is will find a Option with that ID, where Option.id = $someBallotID (which is comparing the worng IDs) my query was lo where Option.ballot_id = $someBallotID --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: Associated Model SELECT statements
Regarding your section question, and pulling only certain information... Check out: http://api.cakephp.org/class_model.html#c2d8fb14f5398c85452d978bd013436f, which is the API page for FindAll(). One of the parameters is 'fields', where you can specify fields returned. I'm not certain, but you might be able to specify something like: array('ballots.*', 'options.*') Again, I'm not sure on that, but it might help. Also in your first question, you wrote: $this->Ballot->Options->findAll("ballot_id=$someID"); . You could also write that as $this->Ballot->Options->findById($someID). The result would be the same, but it looks a little better IMO. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: Associated Model SELECT statements
Oh yea, one more question When I do $this->Ballot->id = $someID; $this->Ballot->read(); I get a huge array with ['Ballot'], ['Options'], and Say I wanted to return only the (['Ballot'] and ['Options']) or (['Ballot'] and ['Votes']), Is there a method/way that will return selective associations in that way? Or, I guess again I'll resort to a custom query... --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Associated Model SELECT statements
A voting system: Model Ballot: hasMany Options,Votes Model Option: belongsTo Ballot Model Vote: belongsTo Ballot Model User: hasMany Votes ^^Im sort of new to MVC, hopefully those associations are OK! Now: some controller code for viewing a ballot: I tried: $this->Ballot->id = $someID $this->Ballot->Options->findAll(); I thought that since Ballot is associated with many options: WHERE `ballot_id` = `Ballot`.`id` that Options->findAll() would only return an array of Options belonging to that Ballot, but actually that call is retrieving ALL rows in the options table right now, I'm using $this->Ballot->Options->findAll("ballot_id=$someID"); Am I doing this correctly? Is there any simpler way to get the result I want? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---