• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MY_Model Base CRUD Model

#51
[eluser]Jamie Rumbelow[/eluser]
It was a bug... but a while ago. Take a look at the source, it should be protected $_table.

Jamie

#52
[eluser]Mafagafo[/eluser]
I'm trying to use the version 1.1.1, but i'm having some dificulties:

- how I can retrieve just 2 columns using MY_Model?
For example, a table with 15 fields but I want to retrieve only 2 fields: name and date. How i can retrieve just these 2 fields? How i can format the date field with the format "%Y-%m-%d %H:%i:%s"?

-Can I use more than 1 argument to create a WHERE condition when I use methods like "get_by()" or "get_many_by()"?

This is a great tool. Congratulations. And sorry about my english.

#53
[eluser]Jamie Rumbelow[/eluser]
Hi Mafagafo,

You'll need to create your own methods to do complex things like this. You can filter out this stuff by calling ActiveRecord methods on CodeIgniter's database class:

Code:
$this->db->select('username, email');
$this->users->get_by('id', 1);

Jamie

#54
[eluser]Buso[/eluser]
Hi, I need some advice on how to organize my models when using base models like the one you created.

Suppose I want to have a reusable cms/blog (something that allows me to create articles, comments, categories, links, tags, etc etc)

Would you create one model for each? Example: Article_m, Comment_m, Category_m, so you can have the table name auto-fetched most of the times?

Or one big model that handles everything?

If each Article has many Comments.. Which model should handle the articles_comments table? (supposing I want to have this sepparate table. Or just imagine any many-to-many situation)

Thanks in advance!

#55
[eluser]Jamie Rumbelow[/eluser]
This is more of a generic MVC question, and always the former! Keep things as separated as possible. When dealing with relationships, try to have a "parent" and "child" (in your case, parent is Article), and have the parent handle the relationships.

Hope this helps,

Jamie

#56
[eluser]Buso[/eluser]
It's just that I never see things like subdirectories inside /models. All the libraries I have seen, they always come with 1 big library, and 1 big model.

Well thanks for your answer, I guess I have to try this method (separate everything) and see what happens.

#57
[eluser]liri[/eluser]
It seems that there's also another good MY_Model option developed by
which is available to reiview at: http://github.com/croxton/MY_Model

Just wondering why not merge the good of both worlds? Croxton's got good support
for more complex operations like joins.



Regards,
Liran.

#58
[eluser]MT206[/eluser]
[quote author="rkjaer" date="1267910407"]Anyone managed to make this support multiple databases? I need this solution for my current project, but had no luck yet. Unfortunately the author Jamie does not have time for this suggested feature Sad[/quote]

I'm not sure if you are still looking for an answer but you might want to take a look at this link. He has implemented a My_Model where you can use multiple databases. The link is:

http://www.lukemacneil.com/code/my-codei...crud-model

#59
[eluser]Keylocker[/eluser]
I am having HUGE problems with memory when I try to use the functions get_many, get_many_by and get_all

here's my controller code
Code:
// List all addresses of a given user
public function index( $user_id = NULL )
{
  $this->load->model('addresses_model', 'addresses');
  $addr = $this->addresses->get_many_by( array('user_id' => $user_id) );

  print_r($addr); //debug
}

in the model
Code:
class Addresses_model extends MY_Model {

public function __construct()
{
  // Load base construct
  parent::__construct();
}
}

The error i get is
Code:
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 40 bytes) in
/application/models/addresses_model.php on line 20

For the record. I tried with $this->db->get() and everything works perfectly. The problem appears just using MY_Model.php
What can I do? Please help.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.