Jonathon Posted March 10, 2012 Share Posted March 10, 2012 Hello! I have a foreign keys that are represented in multiple tables, is there a way to get Yii to recognise more than 1 foreign key comment when generating relationships. I've tried so far CONSTRAINT FOREIGN KEY (id) REFERENCES r_detail(created_by_user), mentions(user_id) Yii just seems to take the last table(column) as the relationship, regardless of what precedes it. Is it even possible what i'm trying to do? I don't know Link to comment Share on other sites More sharing options...
Edward Posted March 10, 2012 Share Posted March 10, 2012 Did you read the Yii agile web development book. Foreign keys were covered for the trackstar app. Yii auto generates table relationships in the model you create, provided you setup your relationships in mysql first. You can add to or edit the relationships in the model. 1 Link to comment Share on other sites More sharing options...
Jonathon Posted March 10, 2012 Author Share Posted March 10, 2012 I don't have that book, I know you can edit them directly in the model, but if possible, I'd rather let Yii do the work by using comments. Link to comment Share on other sites More sharing options...
Edward Posted March 10, 2012 Share Posted March 10, 2012 Yes set the foreign keys prior to generating the model and Gii will do that for you. If you can view the agile web application development with Yii, the relationships are on pg.96 and pg.97. If I was you I would give that book a read through before attempting to use Yii, it covers everything you need to know, but there are a few mistakes in the book so watch out. Link to comment Share on other sites More sharing options...
Jonathon Posted March 10, 2012 Author Share Posted March 10, 2012 Yes I know that Edward, I was the one who suggested to you to use Yii http://www.larryullman.com/forums/index.php?/topic/942-what-frameworks-do-people-like-the-most/. I know how Yii works its DB relationships, I just wanted to know from Larry or a seasoned Yii intermediate/pro (Of which I don't think there are any here accept Larry) if it's possible to do what I'm trying to do. Link to comment Share on other sites More sharing options...
Edward Posted March 11, 2012 Share Posted March 11, 2012 Yes thanks i am very happy you did suggest Yii, it will save a bit of time. I am using Zend Studio 9.01 for my IDE, it works really well with the OOP code, much better than Dreamweaver CS5.5. I have not yet decided on what framework i will go ahead and use i am also looking at Zend Framework, with Zend Studio you can incorporate all into your application easily. Yes i agree its better to see what Larry says, i was just giving you all the info i knew that i thought would help. Take care Johny. Link to comment Share on other sites More sharing options...
Larry Posted March 13, 2012 Share Posted March 13, 2012 Good question, Jonathon. To be clear, this isn't a composite key in another table, but rather the same, single column key that appears in multiple tables? I haven't done that myself but my inclination would be to have the comment in the database include two full CONSTRAINT FOREIGN KEY... statements, perhaps separated by a comma or space. That being said, it wouldn't surprise me if Yii isn't set up to acknowledge this possibility yet. Link to comment Share on other sites More sharing options...
Jonathon Posted March 13, 2012 Author Share Posted March 13, 2012 Yeah, this is say an id of one table that appears in other tables to reference data. I tried quite a few variations of the the Foreign key command, including yours, but sadly they didn't work :-( So it looks like manual updating of the models, which isn't too bad (I don't think, I know you cover it in your guides), so it would have been nice to get a good DB down and Yii just do it for me. Maybe in 2.0! Thanks Larry Link to comment Share on other sites More sharing options...
Larry Posted March 14, 2012 Share Posted March 14, 2012 Sure thing. Thanks for the update! Link to comment Share on other sites More sharing options...
Recommended Posts