Gas ORM |
[eluser]bretticus[/eluser]
So I'm basically new to ORM's. I've decided to give it a spin and see if it actually does "... remove all hassle and ... seriously reduce [my] development time..." I like what I see so far. Just having a hard time wrapping my brain around how to do CRUD with pivot tables. I have two tables: user and role. They have a pivot table called site_user for a many-to-many relationship. The user model starts with... Code: class User extends Gas { and the site model starts with ... Code: class Site extends Gas { So I was thinking perhaps, I could do something like... Code: $user = Gas::factory('user')->find_where(array('email' => '[email protected]')); Of course that throws an undefined method error. How is this supposed to work? I'd really appreciate pointers. Thanks
[eluser]toopay[/eluser]
@bretticus, There are enough hooks point to do extra things within your task. has_and_belongs_to property was intend to works with some schema like Code: # Note that job_user not contain any extra collumn(s) other than user_id and job_id If this is the case, then you could have, in your user model : Code: class User extends Gas { Code: // Somewhere within your application scripts
[eluser]mecharius[/eluser]
Hi Toopay, First of all - I came across GAS a little while ago and think it looks great. I've already built one basic app off it (Electrical Parts Inventory Manager) and I'm working at converting another Doctrine based app to it. The application I am converting has about 20 tables with some complicated relationships between them. I've been looking at these for quite a while and when I read the code everything seems to be ok, but I keep getting an error " Model XXXX located, but missing relationship properties." Do you have any tips for debugging complex relationships? Is there any way we can get a bit more detail out of where the error is occurring? I'm not looking for you to debug my code, more just interested if there is a way I can get more information out of the GAS error! Keep up the great work, Thanks, Will
[eluser]mecharius[/eluser]
OK, I tracked it down by going to line 3032 or thereabouts in the GAS library and just echoing every variable in the Gas::generate_child() function. Strangely enough it looked as though Gas was assuming relationships I hadn't defined? i.e. I had a has_and_belongs_to relationship between Users table and Permissions table which I had deliberately not defined through Gas (i.e. the tables existed but I was manually managing it in code), but Gas seemed to be looking for it?
[eluser]toopay[/eluser]
[quote author="mecharius" date="1328443182"] Strangely enough it looked as though Gas was assuming relationships I hadn't defined? i.e. I had a has_and_belongs_to relationship between Users table and Permissions table which I had deliberately not defined through Gas (i.e. the tables existed but I was manually managing it in code), but Gas seemed to be looking for it?[/quote] Thats true. When the first time core abstraction of Gas loaded, it save all of your model(s) and its properties, into some global entity repository. Thus, if you try to reach unexisted property(es) within your model, eg: Code: $user = Gas::factory('user')->find(1); If you still have some issue on setting up relationship, after read the documentation, feel free to share your schema here, and we could try to resolve it together.
[eluser]mecharius[/eluser]
Thanks, Yeah the relationship is for a nested ACL so it can be a little confusing... I can manage this outside of GAS quite easily and currently have the Users<<HABTM>>Permissions working. I'm just managing the Permissions<<>>Permissions relationship in my code. Code: USER USER_PERMISSION PERMISSION Another interesting relationship that Doctrine supports is linking a table to another table twice by alias... e.g. for private messaging - you can track from_user and to_user both linked by separate IDs based on the schema below. Does that make sense? Code: USER MESSAGE USER Is it possible to implement this kind of relationship? e.g. Code: #USER_GAS.PHP# Anyway, just some thoughts / questions... Thanks for all your work on this library, its great!
[eluser]toopay[/eluser]
@mecharius, You could set up self-referential for the first case, play around with it. Regarding your second case/though, aliasing, while within current version it was impossible(mean you will need to adding extra method by yourself within some model, to handle that), the next version will be far more flexible and set up something like that will be a breeze. Because each relationship no longer based by per-table/model mindset, but based by "path" of entities tuple(s) you defined, something like : http://goo.gl/VVUob (look around line 101-105).
[eluser]Lunaman[/eluser]
Hey Toopay, Trying to use Gas ORM I stumbled upon something I miss from CI form validation. With standard form validation usage there is the possibility to add a readable name to a field for the end-user. I can't seem to find this functionality when using Gas ORM. Is there a way I can get field names replaced with readable names for the end-user? Thanks
[eluser]toopay[/eluser]
@Lunaman, The validator within Gas, already replace your table's collumn name into human-readable name. But if necessary you could also get the raw error(s) and process it by yourself, by accessing 'errors' property. Eg : Code: $data = array('name' => 'Mr.Foo', 'username' => 'foo', 'email' => 'notvalidemail'); |
Welcome Guest, Not a member yet? Register Sign In |